How do I replicate rotating an object towards an angle by X degrees through math?

0 favourites
  • 5 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I have an object with an instance variable simAngle, and then I want to always set the angle of the object to that instance variable. Basically instead of rotating things by the object I want to rotate things through the instance variable and then the object sets its angle as the instance variable.

    How would I simulate rotating an object towards an angle by X degrees through instance variables with math?

    I have something close but the problem is that it won't take the shortest rotation, it will rotate the longest way possible. Is there a formula for this?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • can you set the angle towards another object?

    angle(obj1.x,obj1.y,obj2.x,obj2.y)

  • You mean you want to rotate the sprite smoothly to the target angle?

    You can use one of these methods, run them on every tick:

    Rotate 1 degree towards angle self.simAngle

    or

    Sprite set angle to anglelerp(self.angle, self.simAngle, dt*4)

  • If you’re setting the angle of the sprite then I’d recommend the first method dop posted.

    The lerp gives an ease in but you can have the rotation at a constant speed with:

    Set angle to rotateAngle(self.angle, self.simAngle,100*dt)

    If could also do multiple conditions to see is the one angle is clockwise or counter-clockwise along with the angleDiff(a,b) expression to get the direction and angle difference.

    For a pure math way you can do this with the two angles which will give the difference and clockwiseness.

    signedAngleDiff=angle(0,0,cos(a-b),sin(a-b)

    Abs(signedAngleDiff) is the distance

    signedAngleDiff<0 means a is counter clockwise from b

  • Your math did the trick, thank you so much!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)