Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | javrocks |
When the ball collides with objects it bounces off, but when doing so, it changes the direction of other balls in the scene. Also when the ball collides with another ball it pauses before bouncing off each other.
extends KinematicBody2D
export var ball_speed = 400
var direction = Vector2()
onready var target = get_tree().get_root().find_node("Player", true, false)
export(PackedScene) var ExplosionEffect: PackedScene =
preload("res://Scenes/Explosion.tscn")
func _ready():
global_position = $Position_1.global_position
direction = (target.global_position - global_position).normalized() * ball_speed
func blow_up():
var scene_instance = (ExplosionEffect.instance())
get_tree().current_scene.add_child(scene_instance)
scene_instance.global_position = global_position
scene_instance.get_node(".").scale.x = 1
scene_instance.get_node(".").scale.y = 1
queue_free()
func _physics_process(delta):
$AnimationPlayer.play("Ball_Rotation")
var collision = move_and_collide(direction * delta)
if collision:
if collision.get_collider().is_in_group("Player"):
collision.get_collider().lower_player_health()
blow_up()
if collision:
direction = direction.bounce(collision.normal) # Here's the issue
Try making the other ball instances local to the scene
CollCaz | 2023-05-20 14:18
I turned on local to scene but it still doesn’t work
javrocks | 2023-05-20 18:01
Any other ideas ???
javrocks | 2023-05-24 00:54