Skip to content

Instantly share code, notes, and snippets.

@dirkk0
Created April 16, 2021 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirkk0/fd895c17205c55652a2904ce48635b02 to your computer and use it in GitHub Desktop.
Save dirkk0/fd895c17205c55652a2904ce48635b02 to your computer and use it in GitHub Desktop.
extends KinematicBody
export var speed = 10
export var acceleration = 5
export var gravity = 0.98
export var jump_power = 35
export var mouse_sensitivity = 0.3
var velocity:Vector3
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta):
if Input.is_action_pressed("ui_cancel"):
get_tree().quit()
var direction:Vector3
var aim = $Head/Camera.get_camera_transform().basis
if Input.is_action_pressed("ui_w"):
direction -= aim.z
if Input.is_action_pressed("ui_s"):
direction += aim.z
if Input.is_action_pressed("ui_a"):
direction -= aim.x
if Input.is_action_pressed("ui_d"):
direction += aim.x
if Input.is_action_just_pressed("ui_f"):
pass
direction = direction.normalized()
velocity = velocity.linear_interpolate(direction * speed, acceleration * delta)
velocity.y -= gravity
if Input.is_action_just_pressed("ui_select") and is_on_floor():
velocity.y += jump_power
move_and_slide(velocity, Vector3.UP)
# move_and_slide(velocity, Vector3.UP, false, 4, PI/4, false)
func _input(event):
if event is InputEventMouseMotion:
self.rotate_y(deg2rad(-event.relative.x) * mouse_sensitivity)
# $Head.rotate_y(deg2rad(-event.relative.x) * mouse_sensitivity)
$Head/Camera.rotate_x(deg2rad(-event.relative.y) *mouse_sensitivity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment