(SOLVED) Physics Rotate Toward Mouse

Get help using Construct 2

Post » 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
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
81
S
13
G
7
Posts: 968
Reputation: 10,881

Post » 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,882

Post » 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.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
81
S
13
G
7
Posts: 968
Reputation: 10,881

Post » 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.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
81
S
13
G
7
Posts: 968
Reputation: 10,881

Post » 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?
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
81
S
13
G
7
Posts: 968
Reputation: 10,881

Post » 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,882

Post » 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.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
81
S
13
G
7
Posts: 968
Reputation: 10,881

Post » 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,882

Post » 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
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » 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,882

Next

Return to How do I....?

Who is online

Users browsing this forum: 25games, jatin1726, Resslx and 39 guests