Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- #TODO
- # forward and backward based on where player is looking
- # space bar moves player up Y based on world coords at half mvmnt speed - DONE
- # when pressing left and right, add smooth camera tilt in respective direction
- export var speed = 10
- export var accel = 5
- export var mouse_sense = .09
- onready var head = $Head
- onready var camera = $Head/Camera
- onready var point_camera = $Head/Camera/Point_Camera
- var float_power = speed * .5
- var velocity = Vector3()
- var camera_x_rot = 0
- func _ready():
- #stops mouse pointer escaping game window
- Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
- func _input(event):
- # ESCAPE key
- if Input.is_action_just_pressed("EXIT"):
- get_tree().quit()
- #mouse controls where the player looks
- if event is InputEventMouseMotion:
- head.rotate_y(deg2rad(-event.relative.x * mouse_sense))
- var x_delta = -event.relative.y * mouse_sense
- #locks the camera view to +- 90 degrees
- if camera_x_rot + x_delta > -90 and camera_x_rot + x_delta < 90:
- camera.rotate_x(deg2rad(x_delta))
- camera_x_rot += x_delta
- func _physics_process(delta):
- # get the local trasform of the head spatial node
- var head_basis = head.get_global_transform().basis
- var direction = Vector3()
- # get the direction the player is looking at
- var look_direction = point_camera.get_global_transform().origin - camera.get_global_transform().origin
- if Input.is_action_pressed("move_forwards"):
- # direction -= head_basis.z
- direction += look_direction
- elif Input.is_action_pressed("move_backwards"):
- direction -= look_direction
- # new IF statement so we can move f/b AND r/l at same time
- if Input.is_action_pressed("move_left"):
- direction -= head_basis.x
- elif Input.is_action_pressed("move_right"):
- direction += head_basis.x
- if Input.is_action_pressed("float"):
- direction += head_basis.y
- if Input.is_action_pressed("sink"):
- direction -= head_basis.y
- # if moving f/b AND r/l, it will double the speed unless normalised
- look_direction = look_direction.normalized()
- direction = direction.normalized()
- velocity = velocity.linear_interpolate(direction * speed, accel * delta)
- # move and slide allows collisions for kinematic bodies(i think)
- velocity = move_and_slide(velocity)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement