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 physicsprocess(delta):
if Input.isactionpressed("right"):
velicity.x = speed
if Input.isactionpressed("left"):
velicity.x = -speed
if Input.isactionpressed("forward"):
velicity.z = -speed
if Input.isaction_pressed("backward"):
velicity.z = speed
velicity = moveandslide(velicity)
velicity.x = lerp(velicity.x,0,0.3)
velicity.z = lerp(velicity.z,0,0.3)
func ready():
Input.setmousemode(Input.MOUSEMODECAPTURED)
func _unhandledinput(event):
if event is InputEventMouseMotion and Input.getmousemode() == Input.MOUSEMODECAPTURED:
var movement = event.relative
camera.rotation.x += -deg2rad(movement.y * mousesensitivity)
camera.rotation.x = clamp(camera.rotation.x, deg2rad(-70), deg2rad(70))
rotation.y += -deg2rad(movement.x * mousesensitivity)