Alexandr200P

  • Jul 11, 2022
  • Joined May 18, 2022
  • 0 best answers
  • My character should go as its rotated

    extends KinematicBody
    
    export var speed = 14
    export var sensitivity = 0.01
    export var fall_acceleration = 75
    
    var velocity = Vector3.ZERO
    
    func _physics_process(delta):
    	var direction = Vector3.ZERO
    
    	if Input.is_action_pressed("move_right"):
    		direction.x += 1
    	if Input.is_action_pressed("move_left"):
    		direction.x -= 1
    	if Input.is_action_pressed("move_back"):
    		direction.z += 1
    	if Input.is_action_pressed("move_forward"):
    		direction.z -= 1
    	
    	if direction != Vector3.ZERO:
    		direction = direction.normalized()
    
    	velocity.x = direction.x * speed
    	velocity.z = direction.z * speed
    	velocity.y -= fall_acceleration * delta
    	velocity = move_and_slide(velocity, Vector3.UP)
    
    func _unhandled_input(event):
    	if event is InputEventMouseMotion:
    		rotate_object_local(Vector3.UP, event.relative.x * -sensitivity)
  • func _process(_delta):
    	if Input.is_action_just_pressed("ui_right"):
    		spawn_bullet(Vector2.RIGHT)
    	elif Input.is_action_just_pressed("ui_left"):
    		spawn_bullet(Vector2.LEFT)
    	elif Input.is_action_just_pressed("ui_up"):
    		spawn_bullet(Vector2.UP)
    	elif Input.is_action_just_pressed("ui_down"):
    		spawn_bullet(Vector2.DOWN)