Sinus/Cosinus for movement

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
gencosman
Posts: 2
Joined: Wed Aug 08, 2007 7:56 pm

Sinus/Cosinus for movement

Post by gencosman »

I wanted to make a model move freely in 360°, but when changing direction (+/-45°) the directions change a little. As an example on O° it gets up, +45° and back, the movement goes up with a little to the right.


In class MyEventReceiver : public IEventReceiver:

Code: Select all

case KEY_KEY_Q:
player->angle-=45;
break;
case KEY_KEY_D:
player->angle+=45;
break;
In update()

Code: Select all

myPos.x +=  cos(angle) /10.;
myPos.z +=  sin(angle) /10.;


anms->setRotation ( core::vector3df ( 0,angle,0 ) );
anms->setPosition ( core::vector3df ( myPos.x,myPos.y,myPos.z ) );
What can the problem be?
myPos is a struct with floats.
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

The (co)sinus functions require an argument in radials. Convert with:
radials = degrees * Pi / 180
Or use constant core::GRAD_PI2

Also, maybe your variable angle is not the same one as player->angle
gencosman
Posts: 2
Joined: Wed Aug 08, 2007 7:56 pm

Post by gencosman »

Ok it works ;), thanks.

The example I copied from was some vector math.
Post Reply