Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to move something to rotation of shape?  (Read 2598 times)

0 Members and 1 Guest are viewing this topic.

oOhttpOo

  • Newbie
  • *
  • Posts: 40
    • View Profile
How to move something to rotation of shape?
« 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());
 

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: How to move something to rotation of shape?
« Reply #1 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.
« Last Edit: May 16, 2015, 09:48:53 pm by shadowmouse »

oOhttpOo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: How to move something to rotation of shape?
« Reply #2 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).

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: How to move something to rotation of shape?
« Reply #3 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.

oOhttpOo

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: How to move something to rotation of shape?
« Reply #4 on: May 16, 2015, 09:59:50 pm »
I'll give that a go, thanks  ;)

 

anything