1
votes

I wrote some code down for a kinematic character and only the W key(forward) worked, when I pressed w and d or a that's` when it starts moving but slowly goes left or right. Does anybody know how to fix this?

  extends KinematicBody
var gravity =Vector3.DOWN * 12
var speed = 4
var jump_speed = 6
var spin = 0.1
var velocity = Vector3()
func _physics_process(delta):
    velocity += gravity * delta
    get_input()
    velocity = move_and_slide(velocity,Vector3.UP)
func get_input():
    velocity.x = 0
    velocity.z = 0
    if Input.is_action_pressed("move_UP"):
        velocity.z -= speed
        if Input.is_action_pressed("move_DOWN"):
            velocity.x -= speed
        if Input.is_action_pressed("strafe_Right"):
            velocity.x -= speed
        if Input.is_action_pressed("strafe_Left"):
            velocity.z -= speed
func _unhandled_input(event):
    if event is  InputEventMouseMotion:
        rotate_y(-lerp(0, spin, event.relative.x/10))
        
1

1 Answers

0
votes

Um. Python code? Blocks are controlled by indentation. You've indented all your motion conditionals after move_UP so that they can only be executed if move_UP is active and executed first. Unindent the three "If" statements under the move_UP statement...