Rotation change when bounce.

W

WalkerTxsRngr7

Guest
When I click I have a weapon object spawn in and start moving towards where I clicked. It rotates counter-clockwise if thrown left and clockwise if thrown right. I have this code placed in the create event.
wpn_rtn = 0
if (wpn_throw = 1)//Thrown Left
image_angle += 10
wpn_rtn += 10
if (wpn_throw = 2)//Thrown Right
image_angle -= 10
wpn_rtn -= 10

Then in the step event I have...
image_angle += wpn_rtn

I used a collision event with obj_wall and then bounce against solid objects and code...
wpn_rtn = -sign(wpn_rtn)
wpn_rtn *= 10

I really want the weapon to rotate as it moves and change directions (ccw/cw) when it bounces. Right now it does not keep rotating as it moves. I originally had the two "if..." statements in the step event and it would rotate while it moved but I felt it was resetting the rotation angle every time I tried to change it by bouncing so I moved it to the create and now it doesn't rotate while moving at all.

All help is greatly appreciated!
 
A

Aura

Guest
Maybe you should rotate it depending directly on direction of its motion.

Code:
image_angle += sign(hspeed) * 10;
//or
if (direction > 90 and direction < 270)
{
   image_angle -= 10;
}
else if (direction < 90 or direction > 270)
{
    image_angle -= 10;
}
 
W

WalkerTxsRngr7

Guest
Thanks for the help! I tried it out and I got the first line of code to work but I just had to add a - before the = that way it constantly spins. Who knew something so simple would fix so many lines of code.
 
Top