better velocity check

This commit is contained in:
mightypanders 2021-06-12 13:39:49 +02:00
parent 579190321c
commit 7efa810145
2 changed files with 15 additions and 7 deletions

View File

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

View File

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