How do I get the directional speed without behaviours?

0 favourites
  • 3 posts
From the Asset Store
In this template the music plays without looping in your game
  • Hi,

    my gamepad controls apply axis-speed like this:

    Gamepad.Axis(0,0) * Player.CurrentSpeed * dt[/code:2noza82q]
    
    I try following R0J0hounds suggestion to calculate velocityX like this:
    vx = speed * cos(angleOfMotion)
    
    so I calculate my directional speed like this
    
    [code:2noza82q]Gamepad.Axis(0,0) * Player.CurrentSpeed * dt * cos(angle(0,0,Gamepad.Axis(0,0),Gamepad.Axis(0,1)))[/code:2noza82q]
    
    However when I use this formula in the Predicitve Aim formula from this thread
    
    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?
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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:

    vx=Gamepad.Axis(0,0) * MaxSpeed
    vy=Gamepad.Axis(0,1) * MaxSpeed
    
    x= x+vx*dt
    y= y+vy*dt[/code:vtyzv8xa]
    
    If instead you want some acceleration when using the joystick do this:
    [code:vtyzv8xa]vx = vx + Gamepad.Axis(0,0) * acceleration*dt
    vy = vy + Gamepad.Axis(0,1) * acceleration*dt
    
    x= x+vx*dt
    y= y+vy*dt[/code:vtyzv8xa]
    
    or if you also want a max speed do this:
    [code:vtyzv8xa]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[/code:vtyzv8xa]
  • 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)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)