3d movement and mouse shaking

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

The simplest source code to move a 3D character, as well as how to make the camera rotate by shaking the mouse
Please help me please

Hey, I saw you have problems with the code I provided, so I made minimal project.
Link: Basic Movement.zip

• Download and extract the folder.
• In the Godot project manager click on the “SCAN” button.
• Select the extracted “Basic Movement” folder.

After that you should be able to run the project.

Adam_S | 2020-09-11 20:08

Thank youuuuuuuuuuu

abbos | 2020-09-12 06:57

:bust_in_silhouette: Reply From: Adam_S

Attach this script to a KinematicBody who has a Camera and a CollisionShape as children.

Move: W,A,S,D
Jump: Space
Sprint: Shift

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():

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
        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