I need to create objects in entrance of participant with a ways, so that stops hit with participant instantly. So first, I get the worldwide participant place and route vector which participant in the direction of:
var player_position = participant.remodel.origin var player_forward_vector = participant.global_transform.foundation.z
After which give further distance:
var spawn_position = player_position spawn_position.z -= player_forward_vector.z + 100
After which set the place:
var asteroid_instance = asteroid_scene.occasion() asteroid_instance.remodel.origin = spawn_position
Once I run the sport, first it appears work, nonetheless once I rotated the participant, nonetheless object spawned similar place, not in entrance of the place I am taking a look at.
Here is the video to display:
Why object does not created in entrance of participant, as an alternative maintain spawns in similar location? Any recommendation will very recognize it.
Here is the complete code of spawning object. Word that asteroid is simply Rigidbody object with collision form as little one.
# AsteroidSpawner.gd extends Node onready var participant: Participant = get_tree().get_root().find_node("Participant", true, false) var asteroid_scene: PackedScene = preload("res://Asteroid/Asteroid.tscn") func _ready(): spawn_asteroids() func spawn_asteroids(): whereas true: spawn_asteroid() yield(get_tree().create_timer(2), "timeout") func spawn_asteroid(): var spawn_position: Vector3 = get_spawn_position() var asteroid_instance = asteroid_scene.occasion() asteroid_instance.global_transform.origin = spawn_position # Push in the direction of participant var direction_to_player: Vector3 = participant.remodel.origin - spawn_position var pace = min(rand_range(5, 10), 10) asteroid_instance.add_force(direction_to_player * pace, Vector3()) add_child(asteroid_instance) func get_spawn_position() -> Vector3: var player_position = participant.global_transform.origin var player_forward_vector = participant.global_transform.foundation.z var spawn_position = player_position spawn_position.z -= player_forward_vector.z + 100 return spawn_position