# How do I set player speed relative to gamepad stick pressure

Get help using Construct 2

### » Fri Sep 30, 2016 10:55 pm

Hello,

I thought it would be a fairly easy thing to do but I'm really struggling with this one.

I'm trying to set the player speed relative to the intensity with which the left stick is pushed. (i.e. : The less I push the stick, the slower I am)
I've tried a couple things but nothing seems to work perfectly, especially in 8 directions. Just try and move in circles, it's not exactly smooth.

Thanks in advance.
B
4
Posts: 2
Reputation: 204

### » Sat Oct 01, 2016 12:23 am

To get the best restults, I would recommend using a custom system for movement with an analog stick rather than using the 8-direction behavior. You'll be using angle() and the axis 0 and 1 values to get the angle of the stick, and distance() for the amount with 0,0 as your first two values.

The 8-direction plugin, after all, is meant 8 directions only.
Mistakes were made.
B
61
S
30
G
134
Posts: 1,970
Reputation: 75,442

### » Sat Oct 01, 2016 2:00 pm

I see.
I used what I found in 'How do I create smooth 360 degree movement on a controller?' post for the angle, but I don't really get the distance part.
Right now the player smoothly rotate 360 degrees but how should I tell him to move depending on stick impulse ?

EDIT :

I might have found a not so bad solution.

I attached a bullet behavior to my player rather than an 8 direction. On top of the 360 direction I spoke of earlier, I'm setting the bullet speed relative to which ever gamepad axis value is higher than the other.

It might not be optimal but it does the trick.

Thanks a lot for your help !
B
4
Posts: 2
Reputation: 204

### » Sat Oct 01, 2016 7:31 pm

That's a creative solution! Here is how I was thinking just FYI.

I wouldn't use atan, as you have an extremely slim chance to divide by 0 and I'm not sure how C2 would handle that. Maybe there are safeguards built in and it would be ok, but I'm not sure. Use the angle() expression instead.

I was thinking would be to set angle , then use the action move forward based on distance, or just move at angle.

(I'm assuming axis 0 is x and 1 is y, swap them if I'm wrong)
Angle = angle(0,0,gamepadaxis(0,0),gamepadaxis(0,1)
Distance = distance (0,0,gamepadaxis(0,0),gamepadaxis(0,1)

Optional - Multiply distance by a speed multiplier.
Mistakes were made.
B
61
S
30
G
134
Posts: 1,970
Reputation: 75,442

Return to How do I....?

### Who is online

Users browsing this forum: Google [Bot] and 4 guests