(SOLVED) Physics Rotate Toward Mouse

0 favourites
  • 12 posts
From the Asset Store
Simple resize and rotate events for any sprite, quick and easy event sheet that you can use for your own projects.
  • Hey guys!

    Anyone know of a smart way to have a physics object rotate toward the mouse?

    At the moment, I've applied it to torque, but once the object is facing the correct direction it keeps on going due to momentum.

    Ideally, I need it to start applying torque in the opposite direction when it's half way toward the direction I want to it be, but with the mouse potentially always moving, this is proving to be quite the challenge.

    Any clever folk out there that can figure this out using the physics behaviour?

    CAPX

  • Not tested.

    Firstly do you need to use physics just to rotate your ship - cant you just rotate (sprite) towards mouse position ?

    If physics is the way to go I suggest you look at dampening the sprites rotational angle (physics angular dampening ?)

    Using anglelerp(ships angle,required angle,0.5)*multiplier to give your required torque towards angle(self.x,self.y,mouse.x,mouse.y) might help ?

  • RamPackWobble

    If I control the rotation without physics and the ship collides with something, it doesn't spin out of control.

    If I set the angular dampening to the max, it still wobbles.

    Anglelerp would be good, but only if it eases in, rather than eases out.

  • I know that I can do something similar using custom movement, but I thought physics would make movement slightly different, allowing the ships to crash into other objects and lose control, making movement slightly more 'realisic'.

    It's a real shame objects more or less lose physics when other movements/behaviours are applied.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've tried this again with Custom movement... which unfortunately I cannot see the point of. Deceleration would be a nice feature...

    I've also tried 8 direction movement, which is slightly more useful, but not great.

    Physics gives me an absolutely brilliant result, apart from the rotation! The best result I can have with rotation so far is having the object disable manual rotation upon impact with something, but this isn't exactly what I'm aiming for.

    If I were to be using a keyboard for the rotation, it would be fine, but I'm trying to use the mouse for a more accurate aim.

    Is there anyone out there that can think of a clever way to combine responsive rotation with physics?

  • any better ?

  • RamPackWobble

    Thanks for having a go, but it's very slow to rotate, and if I speed it up the same thing happens with it going back and forth.

  • Then I think you need to alter the thrust depending on the difference in the two angles - bigger angle bigger thrust ?

  • AnD4D,

    Does this work for you? It sets the physics rotation speed according to the angle difference between the mouse position and the sprite angle:

    capx

  • Colludium - Looks good to me - and for that reason "I'm out of here" <img src="smileys/smiley1.gif" border="0" align="middle" />

    (I never even knew there was an "anglediff" or for that matter "Angularvelocity" - too much for my poor brain to take in...)

  • Colludium

    Brilliant! Thank you very much!

  • can you plz reupload the files

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