mmmhhh fixes

This commit is contained in:
SlightlyObscure 2019-11-18 16:39:26 +01:00
parent 892f85e8ad
commit 09ae350b9e
5 changed files with 51 additions and 62 deletions

View File

@ -2,6 +2,7 @@ extends KinematicBody
# export variables
export(NodePath) var body_nodepath
export(NodePath) var lookingAt_nodepath
# const
const GRAVITY = -24.8
@ -16,6 +17,7 @@ const INTERACT_DISTANCE = 5
# private members
var _body: Spatial
var _camera: Camera
var _lookCast: RayCast
var _dir = Vector3();
var _vel = Vector3();
var _is_sprinting;
@ -27,13 +29,14 @@ func _ready():
_camera = $Body/Camera
assert(null != _camera)
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):
process_input()
process_movement(delta)
check_interact()
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))
func check_interact():
if Input.is_action_just_pressed("interact"):
var ray = get_node("Body/Camera/LookingAt")
if ray.is_colliding():
var collider = ray.get_collider()
if _lookCast.is_colliding():
var collider = _lookCast.get_collider()
if "being_touched" in collider:
collider.being_touched = true
@ -103,3 +104,7 @@ func _input(event):
camera_rot.x = clamp(camera_rot.x, -70, 70)
_body.rotation_degrees = camera_rot
if Input.is_action_just_pressed("interact"):
check_interact()
# interact with object player is looking at

View File

@ -11,6 +11,7 @@ collision_layer = 5
collision_mask = 5
script = ExtResource( 1 )
body_nodepath = NodePath("Body")
lookingAt_nodepath = NodePath("Body/Camera/LookingAt")
[node name="Body" type="Spatial" parent="."]

View File

@ -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

View File

@ -1,13 +1,43 @@
extends KinematicBody
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# 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():
pass # Replace with function body.
_startingRotY = global_transform.basis.get_euler().y
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _process(delta):
#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)

View File

@ -1,6 +1,6 @@
[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]