movement 3d , mouse shaking please help

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By abbos

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)

Hi! It’s really difficult to debug someone else’s code as is, but especially if it isn’t formatted as the actual code would be. For starters, could you please try and re-upload the code using the “sample code” button above your text box (as shown by the curly braces icon)?
This will help insure you get the best answers possible.

maxwellc055 | 2020-09-11 17:08

Hi! would you mind to convert this to a comment? As people may wrongly interpret this question is already answered.

p7f | 2020-09-11 18:49

+1 (this should be a comment)

jgodfrey | 2020-09-11 19:08

Ah yes! Of course. Thanks

maxwellc055 | 2020-09-11 19:35

:bust_in_silhouette: Reply From: Tim Martin

Try to read through the code your friend provided. While you might not understand everything that is going on, it’s still mostly in English and is definitely not magic :slight_smile:

Note in particular that the code handling the movement in the X and Z directions (which are the East-West and North-South directions) is based on the WASD keys, not the mouse.

And jumping in the Y direction (Up-Down) is based on the space bar.

maxwellc055’s comment is also valid, it is much harder to read code presented like this than it would be with proper line breaks and formatting.