Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Spatial
- onready var player = get_parent()
- var rotation_helper
- var terminal = null
- #movement variables
- var velocity := Vector3.ZERO
- export (float) var speed = 7.0
- export (float) var gravity = -0.98
- onready var MOUSE_SENSITIVITY = PlayerSettings.settings["Gameplay"]["MouseSensitivity"]
- func _ready():
- Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
- func _unhandled_input(event):
- if event.is_action_pressed("activate"):
- if terminal and player.has_method("activate_terminal"):
- player.activate_terminal(terminal)
- if event.is_action_pressed("reload"):
- if player.has_method("do_reload"):
- player.do_reload()
- if event is InputEventMouseButton:
- if event.button_index == BUTTON_LEFT and event.pressed:
- if player.has_method("do_left_click"):
- player.do_left_click()
- if event.button_index == BUTTON_RIGHT and event.pressed:
- if player.has_method("do_right_click"):
- player.do_right_click()
- if event.is_action_pressed("mouse_release"):
- Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
- elif event.is_action_released("mouse_release"):
- Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
- if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
- rotation_helper = -event.relative.x / 80 * MOUSE_SENSITIVITY
- player.global_rotate(Vector3.UP, rotation_helper)
- func _physics_process(_delta):
- var move_direction := Vector3.ZERO
- move_direction.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
- move_direction.z = Input.get_action_strength("move_back") - Input.get_action_strength("move_forward")
- move_direction = move_direction.normalized()
- move_direction = move_direction.rotated(Vector3.UP, player.global_rotation.y)
- velocity.x = move_direction.x * speed
- velocity.z = move_direction.z * speed
- if not player.is_on_floor():
- velocity.y = gravity * speed
- velocity = player.move_and_slide(velocity, Vector3.UP, true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement