Needing help, with spawning bullets correctly, currently offset/not taking rotation

Godot Version

<4.2.1 , stable>

Question

Ok, so problem when I call func shoot() the bullet spawns fine and is at the correct starting position I think It is just the rotation that is wrong!(I think)!

Code:
screenshot one)
This is the player side of the code.
image

screenshot two)
image

Result:
The bullets spawn just in front of the ship then travel to the left of the orientation of the ship
image

ok, so in your shoot() function, instead of doing

instance.dir = rotation
instance.spawnPos = muzzle.global_position
instance.spawnRot = rotation

try:

instance.global_transform = muzzle.global_transform

then in your bullet’s script
instead of doing velocity and move_and_slide()
try

global_position += transform.y * SPEED* delta

then you wont need the ready function except for setting z_index
the only other thing i think could pose an issue is if your ship’s or muzzle’s scale is not 1, in which case you’d want to use the ready function to make the scale back to 1

also you might need to set the bullet’s top_level == to true

Thank you for your time in trying to help me and also could you explain the changes as I am a bit new and trying to understand why this is happening?

Also unfortunately this does not appear to have worked, However I have tested it out and here are the results.

it also appears as a new user I get only one imbedded image so going to reply with the others

  • With both the suggested changes the spawn point of the bullets is no longer at muzzle but appears to be x0, y0. additionally the off set of the bullet rotation is now to the right of the way the ship faces.

Screenshot 1)

image

Test 1:

  • using only the muzzle global position code, it appear that is what has caused the spawning at x0, y0. However it is hard to see in this next screen shot at the ship is not marked well for the way it is facing but the bullets are back to going left on spawn as in the first post.

  • I did move the mouse a bit
    Screenshot 2)

Test2:

  • Only using the changes to the projectile movement, the bullets again spawn at the ship but now move to the right.
    Screenshot 3)

Screenshot 2)
image

Screenshot 3)
image

1 Like

So screenshot 3 is the one closest to your desired result, right?

Try doing transform.x instead of y. It should then travel along the correct axis. But if it’s going the wrong way just make it -transform.x.

Success:

Ok so this here is the one that got it. - global_position += transform.x * SPEED * delta

Thank you fallen for your time.

Result)

1 Like

You’re welcome, glad it works for you!

1 Like