From 7efa8101453933846c2f27dcedbc9fb804b60087 Mon Sep 17 00:00:00 2001 From: mightypanders Date: Sat, 12 Jun 2021 13:39:49 +0200 Subject: [PATCH] better velocity check --- Guest.gd | 16 ++++++++++------ Guest.tscn | 6 +++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Guest.gd b/Guest.gd index ee615fe..e7de5ec 100644 --- a/Guest.gd +++ b/Guest.gd @@ -1,8 +1,8 @@ -extends KinematicBody2D +extends RigidBody2D onready var pickUpArea = $PickUpArea export var guestName = "Dieter" -export var PICKUPTRESHOLD = 5 +export var PICKUPTRESHOLD = 80 export var destinationColor = Color.yellow signal picked_up(color,name) signal dropped_off_success @@ -21,11 +21,15 @@ var colorList = [ # Called when the node enters the scene tree for the first time. func _ready(): + + #print(get_tree().get_root().get_node("Playa")) + #connect('picked_up',get_tree().get_nodes_in_group("Player")[0], '_on_Guest_picked_up') + rng.randomize() var n = rng.randi_range(0,4) - print(n) + #print(n) destinationColor = colorList[n] - print(destinationColor) + #print(destinationColor) sprite.modulate = destinationColor @@ -35,8 +39,8 @@ func _ready(): func _on_PickUpArea_body_entered(body): print(body.name) if body.name == "Playa": - print(body.velocity) - if body.velocity.x >= PICKUPTRESHOLD and body.velocity.y >= PICKUPTRESHOLD: + print(body.velocity.length()) + if body.velocity.length() <= PICKUPTRESHOLD: emit_signal("picked_up",destinationColor,guestName) # start pickup process diff --git a/Guest.tscn b/Guest.tscn index d8c85ce..a9f5fe8 100644 --- a/Guest.tscn +++ b/Guest.tscn @@ -10,9 +10,10 @@ height = 3.32129 [sub_resource type="CircleShape2D" id=2] radius = 24.5545 -[node name="Guest" type="KinematicBody2D" groups=[ +[node name="Guest" type="RigidBody2D" groups=[ "Guest", ]] +mode = 2 script = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."] @@ -21,6 +22,9 @@ texture = ExtResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) +[node name="Joint" type="PinJoint2D" parent="CollisionShape2D"] +node_a = NodePath("../..") + [node name="PickUpArea" type="Area2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="PickUpArea"]