0 votes

Hi, a friend sent me this code to move in 3D and to rotate the camera by shaking the mouse, but the camera only moves in the y-axis and the character does not move

var speed var gravity = 0 var walk = 10 # walk speed var sprint = 20 # sprint speed var jump = 15 # jump height var fall = 0.7 # fall speed var xsens = 0.08 # mouse x sensitivity var ysens = 0.07 # mouse y sensitivity func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) func _input(event): if event is InputEventMouseMotion: var m = event.relative var r = clamp($Camera.rotation_degrees.x - m.y * ysens,-70,70) $Camera.rotation_degrees.x = r rotation_degrees.y -= m.x * xsens func _physics_process(delta): var dir = Vector3() if Input.is_key_pressed(KEY_SHIFT): speed = sprint else: speed = walk if is_on_floor(): if Input.is_key_pressed(KEY_SPACE): gravity = jump else: gravity = 0 else: gravity -= fall dir.x = int(Input.is_key_pressed(KEY_D)) dir.x -= int(Input.is_key_pressed(KEY_A)) dir.z += int(Input.is_key_pressed(KEY_S)) dir.z -= int(Input.is_key_pressed(KEY_W)) dir = global_transform.basis.xform(dir.normalized()*speed) dir.y = gravity move_and_slide(dir,Vector3.UP)
in Engine by (178 points)

1 Answer

0 votes

You can find and download the answer for your question with this Github link:

by (20 points)
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 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 webmaster@godotengine.org with your username.