# (SOLVED) Physics Rotate Toward Mouse

Get help using Construct 2

### » Sun Jan 26, 2014 8:32 am

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?

CAPXAnD4D2014-01-27 16:57:18
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758

### » Sun Jan 26, 2014 9:11 am

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 ?
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

### » Sun Jan 26, 2014 5:50 pm

@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.
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758

### » Sun Jan 26, 2014 9:26 pm

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.
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758

### » Mon Jan 27, 2014 4:37 am

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?
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758

### » Mon Jan 27, 2014 7:40 am

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

### » Mon Jan 27, 2014 8:45 am

@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.
B
98
S
20
G
8
Posts: 1,066
Reputation: 12,758

### » Mon Jan 27, 2014 8:48 am

Then I think you need to alter the thrust depending on the difference in the two angles - bigger angle bigger thrust ?
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

### » Mon Jan 27, 2014 11:50 am

@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
Learning other engines, but C2 still rocks.
B
80
S
22
G
95
Posts: 2,417
Reputation: 57,671

### » Mon Jan 27, 2014 2:07 pm

@Colludium - Looks good to me - and for that reason "I'm out of here"

(I never even knew there was an "anglediff" or for that matter "Angularvelocity" - too much for my poor brain to take in...)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

Next