#trying to send bullet in the direction it's facing, some axes are flipped under certain conditions

1 messages · Page 1 of 1 (latest)

next badger
#

i'm making a third person shooter. i'm sending projectile bullets from a raycast on the gun scene. when the player is facing roughly -z, everything seems to behave how it should. but as i turn more towards the other direction, the direction of the bullets is flipped vertically. when i'm facing +z, if i aim 30deg down, the bullet will shoot 30deg up, and vice versa. if i'm facing +x or -x, the bullet will just have a flat trajectory and ignore my vertical angle.
the weirdest part to me is that no matter what, the model for the bullet is always pointed in the right direction. i just want to make it move in that direction.
the behavior i'm describing is only after applying a bandaid solution of reversing several axes. if i don't do that, it's weirder and hard to describe.
shooting code:

if Input.is_action_just_pressed("fire"):
        bullet_instance = bullet.instantiate()
    bullet_instance.position = gun_barrel.global_position
    bullet_instance.transform.basis = gun_barrel.global_transform.basis
    get_tree().root.add_child(bullet_instance)```
bullet code:
```func _ready():
        gravity_scale = 0.25
    apply_central_impulse(Vector3(0, 0, -SPEED) * transform.basis * Vector3(-1, -1, 1))```
the last `* Vector3` is the bandaid i was talking about, it helped a lot but there's still this one weird issue. the first -1 makes it go in the right direction horizontally. before that, it would go as far left as i aimed right, so it went straight if i was aiming +z or -z, but if i turned 90deg in either direction, the bullet would go directly towards me. the second -1 just reversed the current issue, it made it so the bullets would be flipped vertically when i'm aiming -z, instead of when i'm aiming +z.
i'm wondering if there's some simple math i can do to just apply another bandaid? it feels like it's really close to working. but i'd also like to know if anyone understands the root cause of this.
thanks
next badger
#

updated with converted format

terse mural
#

what happens if you change position to global_position?

next badger
#

it doesn't seem to change anything

#

just a sec

#

switching to bullet_instance.global_position = gun_barrel.global_position gives the exact same behavior

#

i feel like the x axis is somehow being multiplied by the y axis

#

(this engine's coordinates are confusing, i think that's right though)

#

it's just so weird to me that the bullet always faces in the right direction but can't move in the right direction

terse mural
#

use a rotated() or rotated_local() method if possible

next badger
#

i can try that, but i just feel like i should be able to move it in the direction it's facing without flipping stuff around
it has the exact direction i want right there, it just won't translate to movement

#

i'm worried about covering up something fundamentally wrong

#

FIXED

#

hold on i'm gonna document the full solution

#

thanks for helping though

#

i think what i really needed was that transform.basis.z