- Edited
Hi,
I am having a strange issue, which I can not understand. I'm building a mech game with multiple weapons per mech.
Situation:
I have a rocket launcher, which shall shoot rockets from its position to the target. To do so I add the rocket projectile as a instance, add it to a generic node called dynamic, where I intend to add all indipendent objects such as explosions and projectiles. Then I apply the global_transform of the rocketlauncher muzzle (it is a position 3d node under the mesh node) to the global_transform of the projectile_instance.
My node structue is as follows:
Mech (Spatial)
--> Cockpit (Mesh)
-------> WeaponSlot (Position 3d)
-----------> WeaponNode (Spatial)
---------------> WeaponMesh (Mesh) [Called WEAPON in the script]
-------------------> Muzzle (Position 3d) [MU0, MU1, ... for all 8 Openings the rocketlauncher can shoot from]
func fire(target):
if reload_timer <= 0:
$WEAPON.get_child(current_hp).get_child(0).hide()
print($WEAPON.get_child_count(), " ", current_hp)
var projectile_inst_fire = projectile.instance()
get_node("/root/Spatial/dynamic").add_child(projectile_inst_fire)
projectile_inst_fire.global_transform = $WEAPON.get_child(current_hp).global_transform
projectile_inst_fire.look_at(target,Vector3.UP)
current_hp +=1
if current_hp == ($WEAPON.get_child_count()):
current_hp = 0
reload_timer = 5
The Problem:
Instead of at the rocket launcher position, the rockets are spawned to the side of it.
Does anybody have an Idea why the global position is of?