#3D movement system

1 messages · Page 1 of 1 (latest)

grizzled anchor
#

I am trying to make a 3D movement system that accelerates/decelerates the player instead of just setting their speed to a value. So far it is working prity well and feels smooth, but I have come across an issue. I do not know how I can prevent the player from decelerating when in the air whilst still allowing the player to move around in the air slightly. Here is my code:

func accelerate(delta):
    var temp_vel := velocity
    temp_vel.y = 0
    
    var temp_accel : float
    if !Input.is_action_pressed("run") and is_on_floor():
        target = direction * speed
    else:
        target = direction * run_speed
        
        

    if direction.dot(temp_vel) > 0:
        temp_accel = acceleration
    elif is_on_floor():
        temp_accel = deceleration
        
    if !is_on_floor():
        temp_accel = air_control
    
    
    temp_vel = temp_vel.lerp(target, temp_accel * delta)

    velocity.x = temp_vel.x
    velocity.z = temp_vel.z
#

(Note that this is not all my code, just a snipit from it, the part contolling acceleration and deceleration the "elif is_on_floor(): \n temp_accel = decelation" was my attemps at this but it did not work so far as i can tell)

scenic crater
#

move the if !is_on_floor() to inside the if direction.dot()