How do I get the directional speed without behaviours?

Get help using Construct 2

Post » 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
12
S
4
Posts: 202
Reputation: 1,542

Post » 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) * MaxSpeed
vy=Gamepad.Axis(0,1) * MaxSpeed

x= x+vx*dt
y= 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*dt
vy = vy + Gamepad.Axis(0,1) * acceleration*dt

x= x+vx*dt
y= y+vy*dt


or if you also want a max speed do this:
Code: Select all
vx = vx + Gamepad.Axis(0,0) * acceleration*dt
vy = vy + Gamepad.Axis(0,1) * acceleration*dt

speed = distance(0,0,vx,vy)

if speed > maxSpeed
{
vx = vx*maxSpeed/speed
vy = vy*maxSpeed/speed
}


x= x+vx*dt
y= y+vy*dt
B
88
S
30
G
89
Posts: 5,109
Reputation: 60,329

Post » 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:
Image

Wasn't sure where else the delta time needed to appear, but this seems to do as i intended (from a first glance)
B
12
S
4
Posts: 202
Reputation: 1,542


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests