Created
September 11, 2018 20:22
-
-
Save renamedquery/57273d6d696dd469db7f8042f8a2e8cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends KinematicBody | |
var defaultspeed = 1000 | |
var speed = defaultspeed | |
var direction = Vector3() | |
var gravity = -250 | |
var velocity = Vector3() | |
var mousespeed = 0.005 | |
func _physics_process(delta): | |
speed = defaultspeed | |
direction = Vector3(0, 0, 0) | |
direction = Vector3() | |
if Input.is_action_pressed('ui_left'): | |
direction.x += 10 | |
if Input.is_action_pressed('ui_right'): | |
direction.x -= 10 | |
if Input.is_action_pressed('ui_up'): | |
direction.z += 10 | |
if Input.is_action_pressed('ui_down'): | |
direction.z -= 10 | |
if Input.is_action_pressed('Sprint'): | |
speed += 500 | |
direction = direction.normalized() | |
direction = direction * speed * delta | |
velocity.y = gravity * delta | |
velocity.x = direction.x | |
velocity.z = direction.z | |
if is_on_floor() and Input.is_key_pressed(KEY_SPACE): | |
velocity.y = 50 | |
velocity = move_and_slide(velocity, Vector3(0, 1, 0)) | |
func _input(event): | |
if event is InputEventMouseMotion: | |
rotation.x = clamp(rotation.x - event.relative.y * mousespeed, deg2rad(-180), deg2rad(30)) | |
rotation.y = clamp(rotation.x - event.relative.x * mousespeed, deg2rad(-180), deg2rad(30)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment