Problem with Angles

This forum is currently in read-only mode.
  • Hi, I have a problem with angles and i don't know how to do what I want. In my game, i create a sword, and I want to rotate this sword for 90� then destroy it.

    So my question is : Is there a way, an action, for rotating an object for 90� step by step ?

    I've seen RotateAngle(0, 90, 10) but it doesn't work (or I did something wrong).

    Please help me. Thanks.

  • Hmm, there are many ways to let something rotate. You should use the method that is most suitable. Most of them can (and should) be combined with TimeDelta to enable rotation over time. If you prefer rotation over ticks, that's possible as well.

    First, let's have a look at your proposed RotateAngle(start, end, step). It will rotate the object to step'th-angle between start and end.

    For example:

    RotateAngle(10, 20, 5) will set the angle to 15

    RotateAngle(30, 60, 12) will set the angle to 42

    RotateAngle(90, 50, 8) will set the angle to 82

    To let it rotate over time, combine it with a variable that you raise with TimeDelta on every tick.

    + Sprite: Angle Less than 90

    -> System: Add 90 * TimeDelta to global variable 'myStep'

    -> Sprite: Set angle to RotateAngle(0, 90, global('myStep'))

    This event will let Sprite rotate from 0? to 90? within 1 second (90 * TimeDelta means 90 per second)

    For Sprites, there are also specific expressions for rotation. Rotate clockwise and rotate counter-clockwise will start at the current angle and rotate by the amount given. If the sprite currently has an angle of 0?, then using

    Sprite: Rotate 5 degrees clockwise

    will set the angle to 5 (or rotates by 5 degrees per tick, when used in an always event, for example)

    Mixed with a TimeDelta'd variable you can again rotate it over time:

    + Sprite: Angle Less than 90

    -> Sprite: Rotate 45 * TimeDelta degrees clockwise

    This will rotate within 2 seconds (45 * TimeDelta means 45 per second, a total of 90 is needed == 2 * 45 == 2 seconds)

    You can also directly set the angle and when using lerp() you can get a smooth rotation too:

    + System: Is global variable 'myStep' Less than 1

    -> System: Add 0.5 * TimeDelta to global variable 'myStep'

    -> Sprite: Set angle to lerp(0, 90, global('myStep'))

    With 0.5 * TimeDelta it takes two seconds to raise 'myStep' from 0 to 1 (used as t-value in lerp) and therefor 2 seconds two rotate from 0 to 90

    When working with TimeDelta time has precedence over accuracy. That means, the ending angle might not be exactly 90, but e.g. 90.35762 If you need it to be exactly 90, just add an event:

    + Sprite: Angle Greater than 90

    -> Sprite: Set angle to 90

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi, it's The_Lord_King (it's an another account, I can't access the other...). Thanks for the answer it works like i want, but I have an another problem and i don't know how to solve it except with a lot of events so I hope there is a better solution.

    docs.google.com/open

    This is the picture of what I've done. In my game, I want the sword rotate 90 from the character's angle, so I made a "angleDepart" variable (can be translated by "Start Angle").

    All of this works expect the last event (when the sword's angle is greater than 270).

    Thanks again ! :)

    EDIT : I found the solution sorry for this post. I used "Is Clockwise from" compare.

  • You don't need to excuse a question you had. That's what the help section is for. <img src="smileys/smiley1.gif" border="0" align="middle" />

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