![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | zurolg |
I’m new to coding, so I have no idea how to fix this. Tutorials aren’t helping, so im pretty mad. Walking on WASD works, but when the head/camera looks the other way, the player keep moving in the same direction! Here is my code.I won’t be surprised if it’s something obvious, but I really need your help! much appreciated.
extends KinematicBody
onready var camera = $head/Camera
const gravity = -30
const speed = 10
const mouse_sensitivity = 0.1 #radiants/pixel
var velicity = Vector3(0,0,0)
func _physics_process(_delta):
if Input.is_action_pressed(“right”):
velicity.x = speed
if Input.is_action_pressed(“left”):
velicity.x = -speed
if Input.is_action_pressed(“forward”):
velicity.z = -speed
if Input.is_action_pressed(“backward”):
velicity.z = speed
velicity = move_and_slide(velicity)
velicity.x = lerp(velicity.x,0,0.3)
velicity.z = lerp(velicity.z,0,0.3)
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _unhandled_input(event):
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
var movement = event.relative
camera.rotation.x += -deg2rad(movement.y * mouse_sensitivity)
camera.rotation.x = clamp(camera.rotation.x, deg2rad(-70), deg2rad(70))
rotation.y += -deg2rad(movement.x * mouse_sensitivity)