Laser not coming out of the gun

Godot Version

4.6.1

Question

Hey guys!

In my game, the lasers are not coming out of the gun:

Laser Script and scene:

extends Area2D

var direction: Vector2
var speed: int = 2500

func _ready():
	rotation_degrees += 90
	
func _process(delta: float):
	position += direction * delta * speed
	

func _on_laser_life_timeout():
	queue_free()


func _on_body_entered(body):
	if 'laser_hit' in body:
		body.laser_hit()
	queue_free()

Player laser shoot action script and player scene:

Level scene create laser script:

Aren’t you assigning a global_position of the laser selected position to local position of the laser?

1 Like

whhat?…..I didn’t understand

If u meant to ask if i didn’t get the global position of the selected_laser_pos, of course I did it

That’s what I meant:

Why it matters is that if you now have any offset in either of the bullet’s parents’ position, it would cause your bullet to also be offset, which seems like it’s the case here.

Try assigning a global_position in both cases

2 Likes

I changed position to global_position in the player script too. But still it didn’t make any difference. I think I accidently deleted a line or something. Becasue this code worked till a while before. But when i ran the project, after doing some editings, all of a sudden the laser began to malfunction.

Okay first,it’s kind of hard to tell what’s wrong right now, also it’s a good time to be introduced to version control.

2 Likes

I’d suggest breaking down and isolating the problem, and adding more print() statements to understand where the offset comes from.

1 Like

My guess is that your Laser Spawn Positions node or its children are not where you think they are in space. Since you said this used to work. My guess is you accidentally clicked and grabbed something, creating an unintentional transform. Try checking the position of the Laser Spawn Positions node and make sure it’s (0,0).

Eh…I think i will learn it soooon

Ok I will use print statements and try to find out the problem

I checked it and found no problem with that. the parent node( Laser Spawn Positions) is at (0,0)

Uhh..I didn’t understand

I finally found out the problem!!!

Apparantly the parent node of the scene got displaced from (0, 0). So when a new laser scene was created in the wave arena scene, it too got displaced.

Thank you guys for all your support!

So I was right, I was just too specific about what node it might be. Noted.

2 Likes