SFML community forums

Help => General => Topic started by: oOhttpOo on May 16, 2015, 09:31:41 pm

Title: How to move something to rotation of shape?
Post by: oOhttpOo on May 16, 2015, 09:31:41 pm
Is there a way to move a sprite directly to the rotation of another (with getRotation())? The only way I can think of is to move it in a certain movement for when the other sprite is at every certain rotation, but surely there must be a much simpler and easier way? I tried:
shape1.move(shape2.getRotation());
 
Title: Re: How to move something to rotation of shape?
Post by: shadowmouse on May 16, 2015, 09:47:21 pm
When you say move something to the rotation of the shape what exactly do you mean? The rotation of the shape is a float value that is how much it is rotated around it's origin. If you want to line up object's origins, just use setPosition and getPosition. Btw, move is relative and changes the object's position by an offset, for setting the position to am absolute value, use setPosition.
Title: Re: How to move something to rotation of shape?
Post by: oOhttpOo on May 16, 2015, 09:55:52 pm
Sorry for not being clear, I want to move one shape in the direction of another shape's rotation.
So if the rotating shape has been rotated 20 degrees from it's origin, the other shape would move diagonally (to the same direction of the rotating shape).
Title: Re: How to move something to rotation of shape?
Post by: shadowmouse on May 16, 2015, 09:58:51 pm
Ah, in that case you'll want to use trig equations. So you'll want to use speed*sin(angle) to find the x and speed*cos(angle) to find the y. Then move by those values. The trig functions are in <cmath> and yes, getRotation is right to find the angle.
Title: Re: How to move something to rotation of shape?
Post by: oOhttpOo on May 16, 2015, 09:59:50 pm
I'll give that a go, thanks  ;)