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.
moving acording to a direction
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
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.
Either way, I suggest that you use a tried-and-true mathematical formula, such as spherical coordinates, instead of trying to invent your own.
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 :
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?
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?
and now when i check it agian, i find out its not working so good as i thought!
oh! what should i do?
oh! what should i do?
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.
eh, sorry for not understanding that, dont realy want to bother you guys.
Quote:Original post by Bru
(what's theta? whats phi?
Explained in the first paragraph.
Quote:and what is actually the radius considering i didnt use any radius here up until now).What is 2.5, if not a radius?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement