Particles 2D pushing away instances
Asked Answered
U

4

0

Hey everyone !
Working on a little arcade 2D game where you go from planet to planet (each one being a new center of gravity), i realized that all of the actions my player has creating Particles2D are sometimes pushing away animals (not other rigidbody2Ds) from the center of the planet. I cannot find a link anywhere between those two possibly interracting with each other. Another thing to note is once animals from one planet move away from the center, all other animals move away from theirs ! I cannot for the life of me understand how this is happening. I don't want to flood my own post but I'd post anycode requested.

Thank you so much for reading ! Here's a few pics depicting the problem :

Unroot answered 25/2, 2023 at 10:42 Comment(0)
F
0

Feel free to “flood your own post” with a bit more information on the problem- would help in getting a response.
The behavior you’re describing suggests to me there’s a resource being shared (like a texture) which you thing you’re changing separately while in fact you’re changing all of them because they share the same resource. For those kind of issues, look for the make unique to scene button in the property inspector.

Fleawort answered 25/2, 2023 at 11:16 Comment(0)
U
0

Thank you so much ! Unfortunately i'm creating the animal instances from the planets. Everything's a child of the Level1 node, some created by script others children of the node before starting the program (like the player which i did make local, unfortunately didn't help). Here the codes first of the planets, then of the animals. Sorry, everything is very poorly coded, i'm still learning and hard coding everything !
Thanks again !

Unroot answered 25/2, 2023 at 12:5 Comment(0)
U
0
extends RigidBody2D

var Name = "Planet"
const WASTE = preload("res://SCENES/Waste.tscn")
const ANIMAL = preload("res://SCENES/Animal.tscn")
var PLANT = preload("res://SCENES/Plant.tscn")
var type = 0
var size = 0
var x : int = 0
var pos = Vector2()
var animal_type = 0
var minimap_icon = "planet"


func _ready() -> void:
	###PLANET
	var rng = RandomNumberGenerator.new()
	$Sprite.frame = type
	rng.randomize()
	size = rng.randi_range(0, 3)
	if size == 0 :
		scale = Vector2(0.5,0.5)
	if size == 2 :
		scale = Vector2(2,2)
	if size == 3 :
		scale = Vector2(3,3)
	
	rng.randomize()
	if size < 2 :
		type = rng.randi_range(0, 2)
	elif size > 1 :
		type = rng.randi_range(2, 4)
	
	pos.x = rng.randi_range(-15000, 15000)
	pos.y = rng.randi_range(-15000, 15000)
	position = pos
	
	###ANIMALS
	rng.randomize()
	animal_type = rng.randi_range(0, 2)

func _process(delta: float) -> void:
	###WASTE
	if type == 0 :
		while x < 1 :
			var waste = WASTE.instance()
			var new_waste = waste
			add_child(new_waste)
			
			var plant = PLANT.instance()
			var new_plant = plant
			add_child(new_plant)
			
			var animal = ANIMAL.instance()
			var new_animal = animal
			animal.working_planet_position = position
			animal.type = animal_type
			add_child(animal)
			x += 1
	if type == 1 :
		while x < 2 :
			var waste = WASTE.instance()
			var new_waste = waste
			add_child(new_waste)
			
			var plant = PLANT.instance()
			var new_plant = plant
			add_child(new_plant)
			
			var animal = ANIMAL.instance()
			var new_animal = animal
			animal.working_planet_position = position
			animal.type = animal_type
			add_child(animal)
			x += 1
	if type == 2 :
		while x < 3 :
			var waste = WASTE.instance()
			var new_waste = waste
			add_child(new_waste)
			
			var plant = PLANT.instance()
			var new_plant = plant
			add_child(new_plant)
			
			var animal = ANIMAL.instance()
			var new_animal = animal
			animal.working_planet_position = position
			animal.type = animal_type
			add_child(animal)
			x += 1
			x += 1
	if type == 3 :
		while x < 5 :
			var waste = WASTE.instance()
			var new_waste = waste
			add_child(new_waste)
			
			var plant = PLANT.instance()
			var new_plant = plant
			add_child(new_plant)
			
			var animal = ANIMAL.instance()
			var new_animal = animal
			animal.working_planet_position = position
			animal.type = animal_type
			add_child(animal)
			x += 1
			
	if type == 4 :
		while x < 7 :
			var waste = WASTE.instance()
			var new_waste = waste
			add_child(new_waste)
			
			var plant = PLANT.instance()
			var new_plant = plant
			add_child(new_plant)
			
			var animal = ANIMAL.instance()
			var new_animal = animal
			animal.working_planet_position = position
			animal.type = animal_type
			add_child(animal)
			x += 1
		
		

func _on_Area2D_body_entered(body: Node) -> void:
	if (body.Name == "Planet" and body.name != name) :
		queue_free()
Unroot answered 25/2, 2023 at 12:5 Comment(0)
U
0
extends RigidBody2D

var Name = "Animal"
var working_planet = "none"
var working_planet_position = Vector2(0,0)
var velocity = Vector2()

var color1 = 0
var color2 = 0
var color3 = 0
var type = 0
var action = 0
var action_time = 0
var action_speed = 1

func _ready() -> void :
	var rng = RandomNumberGenerator.new()
	rng.randomize()
	color1 = rng.randf_range(0, 1)
	rng.randomize()
	color2 = rng.randf_range(0, 1)
	rng.randomize()
	color3 = rng.randf_range(0, 1)
	$AnimatedSprite.modulate = Color(color1, color2, color3, 1)
	
	rng.randomize()
	action_speed = rng.randf_range(1,2)


func _process(delta: float) -> void:
	
	
	look_at(working_planet_position)
	rotation_degrees += 270
	var rotating = get_rotation_degrees()
	
	
	var rng = RandomNumberGenerator.new()
	action_time += action_speed
	if action_time >= 100 :
		rng.randomize()
		action = rng.randi_range(0,2)
		action_time = 0
	if action == 0 :
		velocity = Vector2(1, 0).rotated(rotation)
		if $AnimatedSprite.frame > type * 5 + 3 :
			$AnimatedSprite.frame = type * 5
		$AnimatedSprite.flip_h = true
	elif action == 1 :
		velocity = Vector2(-1, 0).rotated(rotation)
		if $AnimatedSprite.frame > type * 5 + 3 :
			$AnimatedSprite.frame = type * 5
		$AnimatedSprite.flip_h = false
	elif action == 2 :
		velocity = Vector2(0,0)
		$AnimatedSprite.frame = type * 5 + 4
	position += velocity

	pass
Unroot answered 25/2, 2023 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.