tethering fixes

This commit is contained in:
mightypanders 2021-06-13 18:05:34 +02:00
parent 451ab8c868
commit a8f6e482c6
3 changed files with 35 additions and 12 deletions

View File

@ -20,14 +20,14 @@ var delivered
enum states {
waiting,
tethered
tethered,
delivered
}
var colorList = [
Color.yellow,
Color.violet,
Color.red,
Color.turquoise,
Color.orange
Color.turquoise
]
var names = [
'Dieter',
@ -42,10 +42,12 @@ var names = [
var currentState = states.waiting
var follow_node = null
var follow_guest = null
var follow_pos = global_position
func _physics_process(delta):
#linear_velocity = linear_velocity.clamped(100)
if currentState == states.waiting:
linear_velocity.move_toward(Vector2.ZERO,5.0)
collision.disabled = false
@ -56,23 +58,33 @@ func _physics_process(delta):
var rot_dir = get_angle_to(follow_pos)
rotation += (rot_dir)
var distance = follow_pos.distance_to(global_position)
global_position = (follow_node.global_position)
global_position = follow_pos
pass
elif currentState == states.delivered:
pickUpArea.monitorable = false
pickUpArea.monitoring = false
collision.disabled = true
func _process(delta):
if delivered != null and OS.get_system_time_msecs() - delivered > 10000:
if delivered != null and OS.get_system_time_msecs() - delivered > 1000:
queue_free()
if visible == false:
follow_node = self
delivered = OS.get_system_time_msecs()
if follow_node != null:
if delivered == null:
delivered = OS.get_system_time_msecs()
currentState = states.delivered
if follow_node != null and follow_node != self:
currentState = follow_node.currentState
if follow_node.visible == false:
follow_node = self
if follow_node == self:
currentState = states.waiting
else:
currentState = states.tethered
follow_pos = follow_node.global_position
follow_pos = follow_node.get_node("Anchor/Joint/Rope/Anchor").global_position
else:
currentState = states.waiting
follow_pos = global_position
@ -86,7 +98,7 @@ func _ready():
if spriteNum % 2 != 0:
$SpriteSam.visible = true
sprite = $SpriteSam
var n = rng.randi_range(0,4)
var n = rng.randi_range(0,colorList.size()-1)
destinationColor = colorList[n]
sprite.modulate = destinationColor
var m = rng.randi_range(0,names.size()-1)

View File

@ -6,10 +6,17 @@ export var ACCELERATION = 60
export var MAX_SPEED = 150
export var FRICTION = 50
enum states {
waiting,
tethered,
delivered
}
var velocity = Vector2.ZERO
var last_in_line
var destinationColor = Color.transparent
var guestName = 'Car'
var currentState = states.tethered
signal scored(value)
var guests = []
@ -27,7 +34,7 @@ func add_Guest_to_Line(parent,guest):
var piece = rope.instance()
parentAnchor.add_child(get_a_pinjoint(parent,piece))
var pieceAnchor = piece.get_node("Anchor")
guest.follow_node = pieceAnchor
guest.follow_node = parent
var pua = guest.get_node("PickUpArea")
pua.monitorable = false
#springJoint.rotation = -rotation
@ -41,6 +48,7 @@ func get_a_pinjoint(parent,piece):
joint.add_child(piece)
joint.disable_collision = false
joint.softness = 10
joint.name = "Joint"
joint.node_a = parent.get_path()
joint.node_b = piece.get_path()
return joint
@ -85,8 +93,9 @@ func remove_Guests_from_Line(color):
for g in guests:
if g.is_in_group('Player'):
continue
if g.follow_node.get_parent() == i:
g.follow_node == g
if g.follow_guest == i:
g.follow_node = g
g.follow_guest = g
var scoreValue = get_score_from_guest(i)
emit_signal("scored",scoreValue)
var pos = guests.find(i)

View File

@ -8,6 +8,8 @@ extents = Vector2( 1, 10 )
[node name="Rope" type="RigidBody2D"]
position = Vector2( 0, 10 )
collision_layer = 0
collision_mask = 0
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]