Sign in to follow this  

moving acording to a direction

This topic is 3291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys. i am trying to make something samilir to a 3D astroids game. i have my 'spaceship' , it can turn left,right,up and down) now i am trying to make it move according to the direction i've set it. i know how to do it in 2D(every frame add cos and sin to x and y with the left\right angle). but since its 3D, i also want it to move up and down acording to the angle of up\down but it just doesnt seem to work :here's the way i am trying to do it
                 velx=-(float)cos(MainPlayer->rotz+rad_90) *2.5;
		 vely=-(float)sin(MainPlayer->rotz+rad_90) *2.5;
		 velz=-(float)tan(MainPlayer->rotx) *2.5;
	     MainPlayer->y+=vely;
	     MainPlayer->x+=velx;
	     MainPlayer->z+=velz;
rotz = the rotation of the ship to the right and left rad_90 = variable containing 90 degree in radian rotx = the rotation of the ship for up and down using this i am getting problems like when i look stright up the ship would suddenly increase speed by way too much. also when velz is possetive, i start moving backwards(i can always manipulate it with -1 when it does, but its probably not the good way to fix it is it?) i'll appreciate help:) thanks in advance.

Share this post


Link to post
Share on other sites
Just by looking at your code, I notice that neither velx nor vely depend on the vertical angle (meaning that the vertical speed will always be independent of the vertical speed, which is unlikely). I also notice that velz is a tangent, which means it can reach infinity (which probably explains why you've been having very high speeds).

Either way, I suggest that you use a tried-and-true mathematical formula, such as spherical coordinates, instead of trying to invent your own.

Share this post


Link to post
Share on other sites
ouch, that page has too many formulas! which one am i actually suppoused to pick?
and well i think i almost reached the my objective by making it this way :

velx=-(float)cos(MainPlayer->rotz+rad_90) *2.5+(float)sin(MainPlayer->rotx) *2.5;
vely=-(float)sin(MainPlayer->rotz+rad_90) *2.5+(float)sin(MainPlayer->rotx) *2.5;
velz=-(float)sin(MainPlayer->rotx) *2.5;
MainPlayer->y+=vely;
MainPlayer->x+=velx;
MainPlayer->z+=velz;

if i remove velx, then it seems to work almost awesomly(though i still didnt find the right formula for velx).
what do you think?

Share this post


Link to post
Share on other sites
thanks :) though i probably should have chosen 5 unit points in math, i find it hard to figure how to turn this into code(what's theta? whats phi? and what is actually the radius considering i didnt use any radius here up until now).
eh, sorry for not understanding that, dont realy want to bother you guys.

Share this post


Link to post
Share on other sites

This topic is 3291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this