Hi it's me again. The question I asked in the OP is perfectly answered. But I would like to use this thread to post my other questions from my first project, so anyone can check the latest progress of the project and see the problem solution better. Please tell me if it's appropriate or not.
This time I got stuck on some physics simulation. I would like to shoot arrow and let it move along a parabola. I want to make it simple so let's say the horizontal velocity of an arrow is a constant value. And during its flight the only force in effect is the gravity.
I tried to use Platform behavior at first, to quickly get the movement and gravity going. The gravity works, but I can't apply a initial speed other than towards angle=0. I found it very confusing that the gravity seems to change its direction when the object's angle changes. So I can't fire the arrow with a upwards angle and expect gravity to work towards bottom.
After messing around for a while I decide to drop all movement behaviors and write the movement logic myself. So I added 3 instance variable "Vx", "Vy", "Gravity" and use dt to calculate the position of the arrow for every tick. I won't describe the events in detail here, you can see it easily in the project.
For some reason I can't get the behavior as I want. No matter how I set up the initial velocity Vy and Gravity, the arrow will always flying downwards. Where did I do wrong?
Also at the end of the event sheet I have a group of event handling the angle of the arrow sprite (just sprite rendering, not angle of movement speed). Since C2 uses clockwise angle it's a bit confusing how to correctly apply trigonometric functions. If you could take a look at that part it would be very helpful to me :D
Here's the download link of the project again:arrowTestGame
Thanks a lot!
EDIT: After I posted this I found the thread discussing about gravity:
And the example posted in this thread is very helpful. I soon realized that I messed up C2 x,y coordinate with math x,y coordinates. I did all my math assuming y is increasing when moving upwards! So stupid...
After that sorted out. My script works finally!
Again all the problem I got so far is due to my lack of knowledge and C2 is very well designed!
Here's the project file that has the correct coordinate setup. If someone has similar question, you can compare the two to see what's wrong.Working Project Filenantas2011-09-08 01:50:07