|
Can't get the right angle... |
armond
Member #8,282
January 2007
|
Hi guys! I thought I could get away with my hacks. But when I needed to track a certain object's angle things started to get messy. In a certain class, I have the following code...
When weapon is fired and releases a projectile... The projectile moves like this... I'm aware that my code(if it ever went well) would move in only 8 directions. But I could live with that. What I don't want is that my projectile doesn't go in the right direction like when I'm on the left side, the enemy would shoot right! Thanks for the help! |
Ceagon Xylas
Member #5,495
February 2005
|
Do you have to use fixed point? I suggest radian. |
armond
Member #8,282
January 2007
|
Thanks for the link. BTW, it seems like functions like fatan, fcos, and fsin requires a fixed type? |
Ceagon Xylas
Member #5,495
February 2005
|
[long time later, I realized I was mistaken. So I rewrote this to just say...] This may be the source of the problem you're having. Try something like this if(s->isVisible()){ float angle=atan2f(targetY-sY,targetX-sX); wc->getCurrentWeapon()->fire(angle); } void Vulcan::update() { if(x < SCREEN_W) { float newX=x+speed*cosf(angle); float newY=y+speed*sinf(angle); move(newX,newY); } }
|
|