random ball linear velocity
This commit is contained in:
@@ -44,24 +44,3 @@ func _on_goal_area_right_body_entered(body):
|
||||
if body_is_ball(body):
|
||||
left_point += 1
|
||||
new_round(body)
|
||||
|
||||
|
||||
func ball_to_racket(body):
|
||||
if body_is_ball(body):
|
||||
var new_linear_velocity = body.linear_velocity * -1
|
||||
|
||||
#if new_linear_velocity.y == 300 and new_linear_velocity.x == 300:
|
||||
# new_linear_velocity.x -= 10
|
||||
# new_linear_velocity.y += 10
|
||||
|
||||
body.linear_velocity = new_linear_velocity
|
||||
print_debug(new_linear_velocity)
|
||||
|
||||
|
||||
func _on_racket_left_body_entered(body):
|
||||
ball_to_racket(body)
|
||||
|
||||
func _on_racket_right_body_entered(body):
|
||||
ball_to_racket(body)
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ shape = SubResource("RectangleShape2D_u7af8")
|
||||
position = Vector2(128, 224)
|
||||
collision_layer = 255
|
||||
collision_mask = 255
|
||||
custom_integrator = true
|
||||
freeze = true
|
||||
continuous_cd = 2
|
||||
max_contacts_reported = 1
|
||||
contact_monitor = true
|
||||
@@ -52,8 +52,7 @@ position = Vector2(1032, 224)
|
||||
collision_layer = 255
|
||||
collision_mask = 255
|
||||
freeze = true
|
||||
custom_integrator = true
|
||||
continuous_cd = 1
|
||||
continuous_cd = 2
|
||||
max_contacts_reported = 1
|
||||
contact_monitor = true
|
||||
metadata/UP_KEY = "right_up"
|
||||
@@ -71,5 +70,3 @@ vertical_alignment = 1
|
||||
|
||||
[connection signal="body_entered" from="GoalAreaLeft" to="." method="_on_goal_area_left_body_entered"]
|
||||
[connection signal="body_entered" from="GoalAreaRight" to="." method="_on_goal_area_right_body_entered"]
|
||||
[connection signal="body_entered" from="RacketLeft" to="." method="_on_racket_left_body_entered"]
|
||||
[connection signal="body_entered" from="RacketRight" to="." method="_on_racket_right_body_entered"]
|
||||
|
||||
@@ -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
|
||||
return Vector2(x_direction, y_direction) * SPEED
|
||||
|
||||
linear_velocity = 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"]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends RigidBody2D
|
||||
|
||||
|
||||
const SPEED = 300.0
|
||||
const SPEED = 500.0
|
||||
|
||||
func _physics_process(delta):
|
||||
if Input.is_action_pressed(get_meta("UP_KEY")):
|
||||
|
||||
Reference in New Issue
Block a user