# How do I get the directional speed without behaviours?

Get help using Construct 2

### » Tue Jan 12, 2016 9:05 pm

Hi,
my gamepad controls apply axis-speed like this:
Code: Select all
`Gamepad.Axis(0,0) * Player.CurrentSpeed * dt`

I try following R0J0hounds suggestion to calculate velocityX like this:
vx = speed * cos(angleOfMotion)

so I calculate my directional speed like this

Code: Select all
`Gamepad.Axis(0,0) * Player.CurrentSpeed * dt * cos(angle(0,0,Gamepad.Axis(0,0),Gamepad.Axis(0,1)))`

However when I use this formula in the Predicitve Aim formula from this thread
what-is-the-formula-for-predictive-aim_t115697?&hilit=predictive+aim&start=10
my baddies miscalculate the angle to hit me when shooting at me.

Using 8direction vectorX and Y for keyboard controls it seems to work great btw ...

I'm guessing that i'm not getting the directional speeds correctly, but the syntax seems beyond me.
Can anyone help?
B
17
S
8
Posts: 266
Reputation: 2,219

### » Tue Jan 12, 2016 9:50 pm

I'm not clear on what you're doing, but I think your formulas are off.

If you're just moving with events and the joystick directly controls the speed do this:
Code: Select all
`vx=Gamepad.Axis(0,0) * MaxSpeedvy=Gamepad.Axis(0,1) * MaxSpeedx= x+vx*dty= y+vy*dt`

If instead you want some acceleration when using the joystick do this:
Code: Select all
`vx = vx + Gamepad.Axis(0,0) * acceleration*dtvy = vy + Gamepad.Axis(0,1) * acceleration*dtx= x+vx*dty= y+vy*dt`

or if you also want a max speed do this:
Code: Select all
`vx = vx + Gamepad.Axis(0,0) * acceleration*dtvy = vy + Gamepad.Axis(0,1) * acceleration*dtspeed = distance(0,0,vx,vy)if speed > maxSpeed{vx = vx*maxSpeed/speedvy = vy*maxSpeed/speed}x= x+vx*dty= y+vy*dt`
B
97
S
36
G
131
Posts: 5,517
Reputation: 83,472

### » Tue Jan 12, 2016 10:03 pm

@R0J0hound Alright, thanks a ton! It seems to work.

For future reference or if you care to double check, this what it looks like:

Wasn't sure where else the delta time needed to appear, but this seems to do as i intended (from a first glance)
B
17
S
8
Posts: 266
Reputation: 2,219