![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | sxkod |
Hi all
I am stuck with projectile math! I have a player in FPS setup with camera being the child of the player. On key press, I want to instance a bullet scene [a rigid body] just in front of camera and then apply_impulse to it to go in the direction camera is facing at the time of firing.
if Input.is_key_pressed(KEY_F):
_proj()
func _proj():
var proji=preload("res://bullet.tscn").instance()
globals.world.add_child(proji)
proji.set_owner(globals.world)
proji.set_translation(firepoint.global_transform.origin)
proji.apply_impulse(firepoint.global_transform.origin,Vector3(0,0,-20))
I have the above code. However the impulse seem to be going towards the global Z-20 rather than the camera / firepoint [a spatial child of camera] direction. I tried camera.global_transform as well and still the same results! I tried just the transform but still the same.
I meant
proji.apply_impulse(firepoint.transform.origin,firepoint.transform.origin*10)
proji.apply_impulse(firepoint.global_transform.origin,firepoint.transform.origin*10)
proji.apply_impulse(firepoint.global_transform.origin,firepoint.transform.origin*Vector3(0,0,-10))
What am I doing wrong?
I am obviously out of my depth!!
Thanks