This site requires JavaScript, please enable it in your browser!
Greenfoot back
Claudiu
Claudiu wrote ...

2022/2/28

Help. How do i turn my actor with the right angle??

Claudiu Claudiu

2022/2/28

#
I want to turn my actor(ball) with the right angle, like when it hits the wall or the brick to turn with the same angle but in the opposite direction.. but i have to know the angle between the actor and the wall it hits
danpost danpost

2022/3/1

#
Claudiu wrote...
I want to turn my actor(ball) with the right angle, like when it hits the wall or the brick to turn with the same angle but in the opposite direction.. but i have to know the angle between the actor and the wall it hits
The reflecting angle is always 180 minus twice the normal to the (tangent at the point of) surface hit minus the current rotation of the ball. So, vertical walls, or hitting a rectangle on its side, (with horizontal normals) would be:
setRotation(180-getRotation());
Horizontal walls, or hitting a rectangle on top or bottom, (with vertical normals) would be:
setRotation(-getRotation());
With horizontal normals (vertical surfaces -- case 1 above) the normal is 0 or 180; and when doubled give 0 or 360, which, therefore can be ignored. With vertical normals (horizontal surfaces -- case 2 above) the normal is 90 or 270; and when doubled give 180 or 540, which, will essentially cancel with the initial 180 rotation (hence, why it is not used there.
You need to login to post a reply.