how to add bullet to forward of character in 3d?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bgegg

i can 2d tutorial about 2d shot.
but,i can not found about 3d shot.

i make code like this.
but not work well.

extends KinematicBody

var get_bullet_scene = load("res://levels/bullet.tscn")

var vector_for_move = Vector3()

func _physics_process(delta):
	vector_for_move = Vector3()
	if Input.is_key_pressed(KEY_UP):
		vector_for_move += transform.basis.z * 10
	if Input.is_key_pressed(KEY_RIGHT):
	if Input.is_key_pressed(KEY_LEFT):
	vector_for_move.y += -15

func _on_Timer_timeout():
	var bullet = get_bullet_scene.instance()
	bullet.set_translation(self.transform.basis.z * 3)
	bullet.apply_impulse(self.transform.basis.z,self.transform.basis.z * 20)
this spawn point wierd.
please help.

:bust_in_silhouette: Reply From: DamonR

It may be because you are using set_translation instead of global_transform.
For example my codes use;

clone.global_transform = self.global_transform

But they are kinematic bodies, yours appear to be rigid bodies.

He docs say you can use set_global_transform (and other spatial methods) as long as they are only used when setting up a rigid body.

Hope this helps.

Thank you very much. It worked fine.
Do you normally use a rigidbody for bullets?

bgegg | 2019-08-24 07:13

Glad it’s working now and that I could help.

I have only used spatial nodes with meshes and areas to simulate where projectiles would be. I have looked into using rigid bodies a bit, as they could be useful for arrows that should arc once fired, rather than fly straight all the time.
But due to being busy (moving), I have not yet been able to fully test this idea.

For bullets, it depends on what effect you want to achieve, they normally move very fast, so a straight line can work better, and you won’tactually see them.
The godot docs cover an FPS tutorial ( FPS tutorial — Godot Engine (3.1) documentation in English ), which uses spatial bullets for the pistol and a raycast for the machine gun (higher rates of fire so you wouldn’t see the bullets), which I used as the basis for my arrows.

DamonR | 2019-08-24 09:16

Thank you
I do not use rigid
No need for now

bgegg | 2019-08-24 20:16