Updating an object's position
I need to be able to add a "Rocket" object into my program whenever the player fires their weapon. I''ve accomplished this, but am having problems with the mathematical aspect. The program keeps track of the player''s current heading and assignes that value to the rocket(heading = player->heading) when the rocket object is created. I''m then able to update the rocket''s (x,z) position with the following math...
x -= sin(heading*piover180)
z -= cos(heading*piover180)
This works perfectly for the (x,z) position.
I also keep track of the player''s Y camera angle. I haven''t been able to use that angle to successfully update the object''s Y position, though. The closest I have come up with is:
y += sin(Yangle*piover180)
This quick fix works for now, but as the angle gets further from the "starting angle" the object follows a "steeper" path that doesn''t represent the camera''s angle. I can minimize the error by multiplying the result like this:
y += 0.7 * sin(Yangle*piover180)
And this causes the object to follow the camera''s angle more closely, but is still not perfect.
Does anyone know how I would go about updating the object''s Y position in a way that is similar to the way I update the X and Z positions? I hope this makes sense to someone.
thanks,
nlowery
A single angle only represents a direction within a plane. Within 3D it takes two angles, i.e. left/right and up/down. Here is a referance for spherical coordinates.
[edited by - LilBudyWizer on January 25, 2003 8:09:04 PM]
[edited by - LilBudyWizer on January 25, 2003 8:09:04 PM]
Keys to success: Ability, ambition and opportunity.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement