Rotation Problem

This forum is currently in read-only mode.
From the Asset Store
For problem solving, puzzles, bubbles, platforms and other adventures.
  • http://dl.dropbox.com/u/9762772/Rotation%20Example.cap

    Can't remember what ver. of Construct I have.

    First post

    Anyways, I'm trying to make a rotation that will smoothly rotate

    towards an angle. By "smoothly", I mean that it will rotate towards

    an angle, then decelerate the more it comes closer to matching that

    specified angle.

    So I got something working. I use two objects, one always points

    towards the specified angle(The mouse position), and Object 2

    will rotate to match Object 1.

    I get the speed at which Object 2 will rotate by taking the 2 separate angles

    and getting the difference between the two, scale that difference

    towards a reasonable "speed" that I want it to rotate at, and then

    incorporate that "speed" into an event.

    The problem with this is that the Object 2 will suddenly accelerate

    once Object 1 hits 360� and snaps back to 0�, then return to a normal

    speed after it also crosses that snap.

    So, is there a way to fix this, or is there an easier way to

    get the kind of rotation I want?

    Been wrapping my brain around this for a while, but I can't come up with anything.

    Cap is a little messy, but I hope it isn't unreadable.

    Thanks for reading!

    EDIT: Typos.

  • The "anglediff(a, b)" expression is a better way to calculate angle differences as is corrects for the 360 to 0 jump.

    Change this

    -> Sprite16: Set 'Angle Speed' to Sprite16.Angle - Sprite162.Angle[/code:3gwp2r86]
    to this
    [code:3gwp2r86]-> Sprite16: Set 'Angle Speed' to anglediff(Sprite16.Angle, Sprite162.Angle)[/code:3gwp2r86]
    and remove event 3
  • This is a really useful piece of code!

    Might I also suggest that you change the '30' in your events to a private variable (I just called it Rotate Speed while playing around with the cap) and then you can quickly fine tune the speed at which your sprite rotates - with 1 being immediate rotation and larger values delaying it.

    Oh and wouldn't something need to be scaled by delta time here?

  • Oh and wouldn't something need to be scaled by delta time here?

    time delta isnt actually needed, its something you add for a desired reaction to lag and refresh rate independance.

    in this case id imagine you'd need to scale the rotation speed, and thats it.

    time delta makes your game "choppy" when it lags, instead of being "slow-mo", which can cause serious problems with collision detection, one reason i avoid using it. an advantage to using it though is that your game can be monitor independent if its using VSYNC, but really, you could just make your game have a fixed 60fps version and a vsync version for 60 Hertz screen users. i think its just as good a solution, seeing as most people have a 60 htz screen anyways.

  • Oh yeah, I just thought it was good practice to use it in any custom (or rather non-behaviour based) movement in Construct?

  • Oh yeah, I just thought it was good practice to use it in any custom (or rather non-behaviour based) movement in Construct?

    well as i said, theres no bad about using either, only different advantages.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks alot, R0J0hound, really saved the day for me!

    This is a really useful piece of code!

    Might I also suggest that you change the '30' in your events to a private variable (I just called it Rotate Speed while playing around with the cap) and then you can quickly fine tune the speed at which your sprite rotates - with 1 being immediate rotation and larger values delaying it.

    Oh and wouldn't something need to be scaled by delta time here?

    The 30 in the cap was going to be replaced by a private variable later on,

    as the example I posted was going to be grafted into my project when

    I had gotten what I wanted done with the rotation, and optimized it some.

    It's now 4 actions in an "always" event.

    Code if you want it;

    Always;
    
    Object1 -> Set Position to Object2
    Object1 -> Set Angle toward (mouseX,mouseY)
    Object1 -> Set variable "RSpeed" to anglediff(Object1.Angle,Object2.Angle)
    Object2 -> Rotate Object1.Value('RSpeed')/10 degrees toward (mousex,mousey)
    [/code:3ra8gguk]
    
    Thanks for looking at it guys, I really appreciate it!
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)