How do I track a full 360 rotation as a Condition?

0 favourites
  • 3 posts
From the Asset Store
Simple and easily editable template for a dynamic camera that zooms in and out based on how far apart the players are.
  • Hello!

    I've been working on a skateboarding game that is partially controlled by mouse x,y.

    -The player can rotate their board in the air freely.

    -I have the board set up as a turret in this scenario, that points to the mouse position in air. Reason for this is so I can adjust the maximum rotation speed, and I figure that it would be part of my solution here. It's also easy to just flip the turret off when the user is on solid ground.

    -Upon a full 360 rotation (from 0 degrees to 360, since the board begins to rotate towards your mouse the moment you jump from 0) the direction of rotation will be identified and set off a variable and continue the trick.

    -I would like to differentiate between front and backflips however I'm willing to settle if that gets too tricky.

    Now, I see a similar thread from a few years ago here and https://www.construct.net/en/forum/construct-2/how-do-i-18/count-rotations-46674 however I can't seem to get a good implementation into my project. The second thread seems to have worked for another user but I don't think I'm understanding it correctly.

    Also question because I'm new to these forums. Is it okay to compound questions or should I make a second thread for an unrelated question for organization/archival sake? Thank you!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here’s an idea to keep track of the total rotation of the an object. You’d want it to run toward the end of the event sheet after anything that rotates the sprite.

    The equation used is a signedAngleDifference, which is like the angleDiff() expression but it gives positive and negative for clockwise and counter clockwise rotation.

    Global totalRot=0
    Global prevAngle=0
    
    Every Tick
    — add angle(0,0,cos(sprite.angle-prevAngle), sin(sprite.angle-prevAngle)) to totalRot
    — set prevAngle to sprite.angle

    So a front flip would be if totalRot>360, and a back flip would be if totalRot<-360.

    In general the number of flips could be calculated with:

    Flips = totalRot>0?floor(totalRot/360):ceil(totalRot/360)

    You’d probably want to reset totalRot to 0 when you first get air born from a jump I’m guessing.

  • Brilliant! Thank you so much R0J0!

    The flips work when going over 360 degrees, but doing a backflip and checking for a rotation <-360 doesn't seem to work, since it starts tracking the board's angle starting at 360 and ends at zero, if that makes sense.

    I'm considering just having it count either rotation however it might be good to just keep the option available if I change my mind in the future.

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