Math code for a rotation speed?

This forum is currently in read-only mode.
  • I'm trying to make a ship rotate at a speed with some inertia. To if the direction to rotate to is flipped than it's not going to instantly turn to the angle at full speed, but rather sow down turning the other way then seed up, exactly like the angular velocity in physics (Which I cannot use for this project)

    I can work it up with code but it would take 4-5 lines with some funkay computations.

    Is there a simple math in Construct that can do this?

  • You could use a private variable to store rotation speed. Whenever you hold down the right or left keys you would either add or subtract a certain amount from this variable. Then you would apply the rotation speed to the object by setting it's angle to: Object.Angle + RotationSpeed * TimeDelta

    Here's a quick example: Inertial Rotation

    Hope this helps.

  • Try Construct 3


    Try Now Construct 3 users don't see these ads
  • Yeah, thanks I had that worked out sort of. But my controls are you turn an arrow that points the direction and the ship rotates to that arrow, and the problem of a rotation speed is that when it reaches the arrow the ship will over shoot it, then slow down, then over shoot the other side then slow down etc.

    Is there some way to get if the ship needs to rotate clockwise and return (1) or counter-clockwise and return (-1)?

  • +Always

    Rotate Ship toward MouseX,MouseY by anglediff(Ship.Angle,angle(Ship.X,Ship.Y,MouseX,MouseY))*timedelta degrees

    You can influence the rotation amount, if the above equation doesn't satisfy you.

  • That doesn't work, if you quickly go to the other side then it's going to snap in the other direction, not have any inertia. Thanks though.

  • Oh, right, momentum. Hmm, now that'd be a little trickier. There is no simple way to do this that I can think of at the moment.

    You'd have to create a 'momentum' variable that you add to whenever the ship thrusts toward desired angle and remove from when you thrust in the opposite direction. That 'momentum' variable would then affect the rotation speed.

  • maybe you could use the anglediff to have some sort of brake, the lesser the anglediff the lower the rotationspeed, when anglediff = 0 the rotationspeed should be 0 , so you wouldn't have overshoot

  • Try something like: always set angle to anglediff*0.9

    The bigger the angle difference, the faster it will turn (there are various ways to cap the speed), and it won't overshoot when it gets to the right angle.

    Also, what I typed won't work exactly because it doesn't have timedelta. It should look like: always set angle to anglediff*(somenumber*timedelta) but I can't remember what somenumber's supposed to be for that. Try experimenting with what number should be there.

Jump to:
Active Users