Hey y’all, throwing a little project together in Godot 4.1 to practice stuff I learned after a tutorial project. I’ve set up two markers as my projectile spawn points, but the shots are spawning slightly off from the markers and I can’t figure out why. Code and pics below. I “fixed” it by shifting the player sprite2D 5 pixels to the right. Not sure why the spawns are being offset though. NVM that only fixed it at the starting position, the shots are way off when rotating. In editor you can see the markers at the two tips on the ship.

In game you can see the shots spawning just to the side of the markers.

Edit: I broke the formatting posting on mobile 🙃

This snippet is from the player script

` var player_direction = (Globals.player_pos - $FixedHardpointDirection.position).normalized()

if Input.is_action_just_pressed("fire_primary") and can_shoot and Globals.laser_ammo > 0 and hardpoint_type == 0:

	Globals.laser_ammo -= 1

	var hardpoint_positions = $ShotStartPositions.get_children()

	can_shoot = false

	$Timers/LaserTimer.start()

	for i in hardpoint_positions:

		player_shot_fixed_weapon.emit(i.global_position, player_direction)

`

And this is from the level script

` func _shoot_fixed_weapon(pos, direction):

var laser = laser_scene.instantiate() as Area2D

laser.position = pos

laser.rotation_degrees = rad_to_deg(Globals.player_rotation)

direction.x = cos(Globals.player_rotation)

direction.y = sin(Globals.player_rotation)

Globals.fixed_hardpoint_direction = Vector2(direction.x,direction.y)

print(Globals.fixed_hardpoint_direction)

laser.direction = Globals.fixed_hardpoint_direction.rotated(-1.5708)

$Projectiles.add_child(laser)

`

  • @TaZ
    link
    2
    edit-2
    1 year ago

    Is the laser sprite positioned at the origin of the laser scene?

    Edit: I see you’re giving the global position of the hardpoint into the emitted signal, and the script that spawns the laser instance assigns a value to the local position of the instance. Perhaps that could explain it? In other words: is the origin of $Projectiles at Global 0,0?

    • @daddybutterOP
      link
      31 year ago

      Ahhhhh you genius haha… For some reason my level parent node was shifted 5 pixels which was then throwing everything off. It’s all lined up now, thank you so much!

      • @TaZ
        link
        11 year ago

        You’re welcome!