The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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.is
actionpressed("right"):
velicity.x = speed
if Input.is
actionpressed("left"):
velicity.x = -speed
if Input.is
actionpressed("forward"):
velicity.z = -speed
if Input.is
action_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.set
mousemode(Input.MOUSEMODECAPTURED)
func _unhandled
input(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 * mouse
sensitivity)

Godot version 3.2.3
in Engine by (12 points)

1 Answer

+1 vote

That is because your velocity is always forward.
try putting this line before calling move_and_slide()

velicity = velicity.rotated(rotation)

It will probably mess with the lerping you are doing after calling move_and_slide() so replace those to lines with:

velicity = velicity.linear_interpolate(Vector3.ZERO,0.3)
by (2,018 points)

Thank you so much! I will try this immediately.(May I ask again in case if anythyng goes wrong?thx again)

Hello again.I am so sorry to bother you, but I need an advise again. Replacing lerping worked, but the first line disabled the entire code for some reason??? I suspect it may be some godot's settings or wersion's fault, but i haven't seen any tutorials about my problem so maybe i should continue searching how to solve this.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.