Help with shooting projectile where player faces

Godot Version



hi, i have a top down shooter i’m making and i can’t seem to figure out how to spawn a projectile. I used a marker2d to get the location where i want to spawn the projectile which is an area2d but it doesn’t work. I get the error

Invalid set index ‘global_postion’ (on base: ‘Area2D (’) with value of type ‘Vector2’.

i get this whenever i try to use the shoot function in my code

also if anyone could help me with how to go about making the projectile move in the direction it was fired, that’d be really helpful as well. I’ve been struggling with this for days now. Here’s the player movement code for context

You spelled “position” as “postion”.

1 Like

I teach coding as a job, and I can confirm that 6/10 times, the errors people have are spelling errors

1 Like

What is your intent here? It looks like you want to use right and left to rotate, and up to move forward. What is the problem you’re trying to solve?

Instead of directly setting rotation, try using the rotate function:

    if ...:
        rotate(diff * delta)

Instead of moving using position, use move_and_slide() or move_and_collide() from within _physics_process(). Moving with position will not use collision detection.

I have found it easier to maintain separate vectors for each direction, then combine them to set the velocity vector.

Oh my goodness lol. Thank you, I didn’t notice

Oh. I’ll look at the documentation and learn how to use those functions, thank you.
My intent is to get the projectile(bullet) to move in a straight line depending on where the player is facing or I guess the angle it’s rotated to. I don’t have the slightest clue of how to go about doing this.