This site requires JavaScript, please enable it in your browser!
Greenfoot back
Wes1731
Wes1731 wrote ...

2011/4/5

Removing Object at height of parabola?

Wes1731 Wes1731

2011/4/5

#
Hello, I'm in high school and am in my second year of programming with Greenfoot. I just have a quick question. How can I make an object be removed from the world when it reaches the maximum height of a parabola? I know how to remove the object, I just don't know how to let the object know that it's at the top of the parabola. In this case, an object is being fired up from a cannon. Any help is appreciated!
mik mik

2011/4/5

#
If you are moving the object along the parabola, then you could just check the y delta at each step. While you fly up, the y delta (difference between current and next position) should be negative. Once the delta gets to zero or positive, you've reached the peak.
PiRocks PiRocks

2011/4/9

#
If your parabola is quadratic (ax^2 + bx + c), then the top of the parabola is in the exact middle of the two solutions. Since you're in highschool, I'm going to assume you know how to do this. If you are using the same parabola every time, you can pre-calculate this point, otherwise you should probably use the quadratic formula and calculate the point before the object is launched because the game might lag during the calculation.
You need to login to post a reply.