random ball linear velocity
This commit is contained in:
@@ -1,21 +1,25 @@
|
||||
extends RigidBody2D
|
||||
|
||||
|
||||
const SPEED = 300.00
|
||||
const SPEED = 500.00
|
||||
|
||||
|
||||
func _ready():
|
||||
func get_random_linear_velocity():
|
||||
randomize()
|
||||
|
||||
global_position = Vector2(640, 360)
|
||||
|
||||
|
||||
var x_direction = pow(-1, randi() % 2)
|
||||
var y_direction = pow(-1, randi() % 2)
|
||||
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
|
||||
linear_velocity = Vector2(x_direction, y_direction) * SPEED
|
||||
return Vector2(x_direction, y_direction) * SPEED
|
||||
|
||||
func _ready():
|
||||
global_position = Vector2(640, 360)
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
linear_velocity = get_random_linear_velocity()
|
||||
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
|
||||
func _on_body_entered(body):
|
||||
linear_velocity = get_random_linear_velocity()
|
||||
|
||||
@@ -15,6 +15,8 @@ gravity_scale = 1.66533e-16
|
||||
can_sleep = false
|
||||
lock_rotation = true
|
||||
freeze_mode = 1
|
||||
max_contacts_reported = 10
|
||||
contact_monitor = true
|
||||
linear_damp_mode = 1
|
||||
script = ExtResource("1_vsr7q")
|
||||
|
||||
@@ -25,3 +27,5 @@ offset_bottom = 40.0
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(20, 20)
|
||||
shape = SubResource("RectangleShape2D_bdxrg")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
|
||||
Reference in New Issue
Block a user