mmmhhh fixes
This commit is contained in:
parent
892f85e8ad
commit
09ae350b9e
@ -2,6 +2,7 @@ extends KinematicBody
|
|||||||
|
|
||||||
# export variables
|
# export variables
|
||||||
export(NodePath) var body_nodepath
|
export(NodePath) var body_nodepath
|
||||||
|
export(NodePath) var lookingAt_nodepath
|
||||||
|
|
||||||
# const
|
# const
|
||||||
const GRAVITY = -24.8
|
const GRAVITY = -24.8
|
||||||
@ -16,6 +17,7 @@ const INTERACT_DISTANCE = 5
|
|||||||
# private members
|
# private members
|
||||||
var _body: Spatial
|
var _body: Spatial
|
||||||
var _camera: Camera
|
var _camera: Camera
|
||||||
|
var _lookCast: RayCast
|
||||||
var _dir = Vector3();
|
var _dir = Vector3();
|
||||||
var _vel = Vector3();
|
var _vel = Vector3();
|
||||||
var _is_sprinting;
|
var _is_sprinting;
|
||||||
@ -27,13 +29,14 @@ func _ready():
|
|||||||
_camera = $Body/Camera
|
_camera = $Body/Camera
|
||||||
assert(null != _camera)
|
assert(null != _camera)
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
get_node("Body/Camera/LookingAt").cast_to = Vector3(0, 0, INTERACT_DISTANCE)
|
_lookCast = get_node(lookingAt_nodepath) as RayCast
|
||||||
|
_lookCast.cast_to = Vector3(0, 0, INTERACT_DISTANCE)
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
process_input()
|
process_input()
|
||||||
process_movement(delta)
|
process_movement(delta)
|
||||||
check_interact()
|
|
||||||
|
|
||||||
|
|
||||||
func process_input():
|
func process_input():
|
||||||
@ -86,10 +89,8 @@ func process_movement(delta):
|
|||||||
_vel = move_and_slide(_vel, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
|
_vel = move_and_slide(_vel, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
|
||||||
|
|
||||||
func check_interact():
|
func check_interact():
|
||||||
if Input.is_action_just_pressed("interact"):
|
if _lookCast.is_colliding():
|
||||||
var ray = get_node("Body/Camera/LookingAt")
|
var collider = _lookCast.get_collider()
|
||||||
if ray.is_colliding():
|
|
||||||
var collider = ray.get_collider()
|
|
||||||
if "being_touched" in collider:
|
if "being_touched" in collider:
|
||||||
collider.being_touched = true
|
collider.being_touched = true
|
||||||
|
|
||||||
@ -103,3 +104,7 @@ func _input(event):
|
|||||||
camera_rot.x = clamp(camera_rot.x, -70, 70)
|
camera_rot.x = clamp(camera_rot.x, -70, 70)
|
||||||
_body.rotation_degrees = camera_rot
|
_body.rotation_degrees = camera_rot
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("interact"):
|
||||||
|
check_interact()
|
||||||
|
# interact with object player is looking at
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ collision_layer = 5
|
|||||||
collision_mask = 5
|
collision_mask = 5
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
body_nodepath = NodePath("Body")
|
body_nodepath = NodePath("Body")
|
||||||
|
lookingAt_nodepath = NodePath("Body/Camera/LookingAt")
|
||||||
|
|
||||||
[node name="Body" type="Spatial" parent="."]
|
[node name="Body" type="Spatial" parent="."]
|
||||||
|
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
extends KinematicBody
|
|
||||||
|
|
||||||
# export variables
|
|
||||||
export(bool) var being_touched
|
|
||||||
|
|
||||||
# const
|
|
||||||
const OPENING_SPEED = 50
|
|
||||||
|
|
||||||
# private members
|
|
||||||
var _startingRotY
|
|
||||||
var _isMoving = false
|
|
||||||
var _isOpening = false
|
|
||||||
var _degrees = 0
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
|
||||||
_startingRotY = global_transform.basis.get_euler().y
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta):
|
|
||||||
#if Input.is_action_just_pressed("interact"):
|
|
||||||
if being_touched:
|
|
||||||
_isMoving = true
|
|
||||||
_isOpening = !_isOpening
|
|
||||||
being_touched = false
|
|
||||||
|
|
||||||
if _isMoving:
|
|
||||||
doorMove(delta)
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
func doorMove(delta):
|
|
||||||
if _isOpening:
|
|
||||||
if _degrees < 100:
|
|
||||||
_degrees += OPENING_SPEED * delta
|
|
||||||
else:
|
|
||||||
_degrees = 100
|
|
||||||
_isMoving = false
|
|
||||||
else:
|
|
||||||
if _degrees > 0:
|
|
||||||
_degrees -= OPENING_SPEED * delta
|
|
||||||
else:
|
|
||||||
_degrees = 0
|
|
||||||
_isMoving = false
|
|
||||||
rotate_y(_degrees * PI/180 - global_transform.basis.get_euler().y + _startingRotY)
|
|
||||||
pass
|
|
@ -1,13 +1,43 @@
|
|||||||
extends KinematicBody
|
extends KinematicBody
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
# export variables
|
||||||
# var a = 2
|
export(bool) var being_touched
|
||||||
# var b = "text"
|
|
||||||
|
# const
|
||||||
|
const OPENING_SPEED = 50
|
||||||
|
|
||||||
|
# private members
|
||||||
|
var _startingRotY
|
||||||
|
var _isMoving = false
|
||||||
|
var _isOpening = false
|
||||||
|
var _degrees = 0
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
pass # Replace with function body.
|
_startingRotY = global_transform.basis.get_euler().y
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
#func _process(delta):
|
func _process(delta):
|
||||||
# pass
|
#if Input.is_action_just_pressed("interact"):
|
||||||
|
if being_touched:
|
||||||
|
_isMoving = true
|
||||||
|
_isOpening = !_isOpening
|
||||||
|
being_touched = false
|
||||||
|
|
||||||
|
if _isMoving:
|
||||||
|
doorMove(delta)
|
||||||
|
|
||||||
|
func doorMove(delta):
|
||||||
|
if _isOpening:
|
||||||
|
if _degrees < 100:
|
||||||
|
_degrees += OPENING_SPEED * delta
|
||||||
|
else:
|
||||||
|
_degrees = 100
|
||||||
|
_isMoving = false
|
||||||
|
else:
|
||||||
|
if _degrees > 0:
|
||||||
|
_degrees -= OPENING_SPEED * delta
|
||||||
|
else:
|
||||||
|
_degrees = 0
|
||||||
|
_isMoving = false
|
||||||
|
rotate_y(_degrees * PI/180 - global_transform.basis.get_euler().y + _startingRotY)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Things/Door.gd" type="Script" id=1]
|
[ext_resource path="res://Things/Door/Door.gd" type="Script" id=1]
|
||||||
|
|
||||||
[sub_resource type="CubeMesh" id=1]
|
[sub_resource type="CubeMesh" id=1]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user