Drag to rotate - question

Hi everyone!

I'm working on a game that allows the player to drag anywhere on the screen to rotate an actor. I've got it working now like so:

When mouse button is down:
Change Attribute
self.X to game.Mouse.Position.X
Constraint Attribute
self.Motion.AngularVelocity to -(game.Mouse.Position.X - self.X)*3
Otherwise:
self.Motion.AngularVelocity to 0

The good thing is that the player can drag around anywhere and the actor's rotation will respond correctly.

The bad thing is that, depending on exactly where the player initiates the drag, the speed and direction of the rotation sometimes feels right and sometimes feels bogged down.

For example, if the player starts the drag at the left of the screen and drags to the right, the actor will rotate clockwise, gaining speed as the drag approaches the right side of the screen. BUT if they don't release the drag and start dragging back towards the left, it only slows the speed of the clockwise drag until they reach the initial drag point --- leaving only a little bit of room to build up a counter-clockwise rotation.

I'd like to have the drag reinitialize itself, so to speak, each time the drag changes direction. If the player drags right, then left, then right again, I want the actor to rotate CW, CCW, CW just as quickly.

I'm not sure I've explained it correctly, but I feel like it gets more muddy each time I retype a different explanation...

Any and all help is appreciated!

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    Make two attributes:
    startingAngle (type = real)
    startingX (type = real)

    When mouse button is down
      Change Attribute: self.startingAngle To: self.Rotation
      Change Attribute: self.startingX To: game.Touches.Touch 1.X
      Constrain Attribute: self.Rotation To: self.startingAngle+(game.Touches.Touch 1.X - self.startingX)
    
  • AdrenalineAdrenaline Member Posts: 523

    @RThurman said:
    Make two attributes:
    startingAngle (type = real)
    startingX (type = real)

    When mouse button is down
    Change Attribute: self.startingAngle To: self.Rotation
    Change Attribute: self.startingX To: game.Touches.Touch 1.X
    Constrain Attribute: self.Rotation To: self.startingAngle+(game.Touches.Touch 1.X - self.startingX)

    Thank you, I'll try this when I get home tonight. I was cooking up a much more elaborate solution so I'd love if this did the trick instead.

  • AdrenalineAdrenaline Member Posts: 523

    This worked like a charm, thank you @RThurman !

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    No problem!

Sign In or Register to comment.