inheritance is hard
This commit is contained in:
27
Examples/mvp-walk-with-collision/Entities/Characters/Movers/pedal.gd
Executable file → Normal file
27
Examples/mvp-walk-with-collision/Entities/Characters/Movers/pedal.gd
Executable file → Normal file
@@ -1,12 +1,12 @@
|
||||
extends Node
|
||||
|
||||
var speed = 1
|
||||
var speed = 1.0
|
||||
|
||||
func to_move_rotate(delta: float):
|
||||
func to_move_rotate(global_transform, delta: float):
|
||||
var mv = Vector3.ZERO
|
||||
var rot = Vector3.ZERO
|
||||
var rot = 0.0
|
||||
for state in _states():
|
||||
var duo = _duo_for_state(delta, state)
|
||||
var duo = _duo_for_state(global_transform, delta, state)
|
||||
mv += duo[0]
|
||||
rot += duo[1]
|
||||
return [mv, rot]
|
||||
@@ -64,8 +64,9 @@ func _states_turning():
|
||||
return [STATE_TURNING_RIGHT]
|
||||
return []
|
||||
|
||||
func _duo_for_state(delta: float, state):
|
||||
func _duo_for_state(global_transform, delta: float, state):
|
||||
var direction = Vector2.ZERO
|
||||
var rotation = 0.0
|
||||
match state:
|
||||
STATE_MOVING_FORWARD:
|
||||
direction.y = -1
|
||||
@@ -76,23 +77,21 @@ func _duo_for_state(delta: float, state):
|
||||
STATE_MOVING_RIGHT:
|
||||
direction.x = 1
|
||||
STATE_TURNING_LEFT:
|
||||
pass
|
||||
rotate_object_local(Vector3.UP, speed * delta)
|
||||
rotation = speed * delta
|
||||
STATE_TURNING_RIGHT:
|
||||
pass
|
||||
rotate_object_local(Vector3.UP, -speed * delta)
|
||||
rotation = -speed * delta
|
||||
STATE_IDLE:
|
||||
pass
|
||||
if direction == Vector2.ZERO:
|
||||
return [Vector3.ZERO, Vector3.ZERO]
|
||||
return [Vector3.ZERO, rotation]
|
||||
direction = direction.normalized()
|
||||
|
||||
var forward = global_transform.basis.z
|
||||
var right = global_transform.basis.x
|
||||
var relative_direction = (forward * direction.y + right * direction.x)
|
||||
|
||||
relative_direction.x *= speed
|
||||
relative_direction.z *= speed
|
||||
relative_direction.y = -speed
|
||||
relative_direction.x *= speed * delta
|
||||
relative_direction.z *= speed * delta
|
||||
#relative_direction.y = -speed
|
||||
|
||||
return [relative_direction, Vector3.ZERO]
|
||||
return [relative_direction, rotation]
|
||||
|
||||
Reference in New Issue
Block a user