1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- extends KinematicBody
- # physics
- var moveSpeed : float = 5.0
- # cam look
- var minLookAngle : float = -90.0
- var maxLookAngle : float = 90.0
- var lookSensitivity : float = 10.0
- # vectors
- var vel : Vector3 = Vector3()
- var mouseDelta : Vector2 = Vector2()
- onready var camera : Camera = get_node("Camera")
- func _ready():
- move_and_slide(Vector3(60.503445, 30.231335, 1734.286987) + Vector3(0,0,10), Vector3.UP)
- func _process(delta):
- # rotate the camera along the x axis
- camera.rotation_degrees.x -= mouseDelta.y * lookSensitivity * delta
-
- # clamp camera x rotation axis
- camera.rotation_degrees.x = clamp(camera.rotation_degrees.x, minLookAngle, maxLookAngle)
-
- # rotate the player along their y-axis
- rotation_degrees.y -= mouseDelta.x * lookSensitivity * delta
-
- # reset the mouseDelta vector
- mouseDelta = Vector2()
-
- func _input(event):
-
- if event is InputEventMouseMotion:
- mouseDelta = event.relative
- func _physics_process(delta):
-
- # reset the x and z velocity
- vel.x = 0
- vel.y = 0
- vel.z = 0
-
- var input = Vector3()
-
- # movement inputs
- if Input.is_action_pressed("move_forward"):
- input.y -= 1
- if Input.is_action_pressed("move_backward"):
- input.y += 1
- if Input.is_action_pressed("move_left"):
- input.x -= 1
- if Input.is_action_pressed("move_right"):
- input.x += 1
- if Input.is_action_pressed("move_up"):
- input.z += 1
- if Input.is_action_pressed("move_down"):
- input.z -= 1
-
- input = input.normalized()
-
- # get the forward and right directions
- var forward = global_transform.basis.z
- var right = global_transform.basis.x
- var up = global_transform.basis.y
-
- var relativeDir = (forward * input.y + right * input.x + up * input.z)
-
- var moveSpeed2 = moveSpeed
- if Input.is_action_pressed("sprint"):
- moveSpeed2 = moveSpeed * 3
- # set the velocity
- vel.x = relativeDir.x * moveSpeed2
- vel.z = relativeDir.z * moveSpeed2
- vel.y = relativeDir.y * moveSpeed2
-
- # move the player
- vel = move_and_slide(vel, Vector3.UP)
-
-
|