blob: 9953d16fc208550b2e0d4188bdb3ef64b81856af (
plain) (
tree)
|
|
extends KinematicBody
export var speed = 20
export var ang_speed = PI
export var mouse_dpi = 0.2
export var pitch_min = -0.8
export var pitch_max = 0.8
func joystick(neg_x: String,pos_x: String,neg_y: String,pos_y: String):
var joystick = Input.get_vector(neg_x,pos_x,neg_y,pos_y)
var joystrength = abs(joystick.length())
if joystick != Vector2.ZERO:
joystick = joystick.normalized()
return Vector3(joystick.x,joystick.y,joystrength)
func _physics_process(delta):
var d_ang_speed = ang_speed * delta
var rotation = Transform(self.rotation, Vector3.ZERO)
var up = rotation * Vector3.UP
var forward = rotation * Vector3.FORWARD
var right = rotation * Vector3.RIGHT
var stick = joystick("move_left", "move_right", "move_back", "move_forward")
var movement = Vector3.ZERO
movement += right * stick.x * stick.z * speed
movement += forward * stick.y * stick.z * speed
if Input.is_action_pressed("move_up"):
movement += up * speed
if Input.is_action_pressed("move_down"):
movement -= up * speed
movement = move_and_slide(movement, Vector3.UP)
stick = joystick("look_right", "look_left", "look_down", "look_up")
var mouse_movement = MouseInput.get_mouse_movement()
if stick.z == 0.0:
stick.z = mouse_movement.length() * mouse_dpi
mouse_movement = -mouse_movement.normalized()
stick.x = mouse_movement.x
stick.y = mouse_movement.y
var pitch = forward.dot(Vector3.UP)
if (pitch >= pitch_min and stick.y < 0) or (pitch <= pitch_max and stick.y > 0):
rotate(right, stick.y * stick.z * d_ang_speed)
rotate(Vector3.UP, stick.x * stick.z * d_ang_speed)
|