So in this particular game I’m using LateUpdate() to set the position of the players spine, and attached to the players hand is a weapon, under the weapon I have Transforms set up as spawn points that are used for prefab instantiation. Here’s the bit of code showing the instantiation.
void SpawnShell () {
if (shellPrefab == null)
return;
if (shellSpawn == null) {
Debug.Log ("Weapon::SpawnWeaponEffects -- For the shell to spawn you need to fill in the 'shellSpawn' slot.");
return;
}
if (shellPrefab.GetComponent<Rigidbody> () == null) {
Debug.LogError ("Weapon::SpawnShell -- For the shell to spawn you need a rigidbody component attached.");
return;
}
GameObject shell = (GameObject)SimplePool.Spawn (shellPrefab, shellSpawn.position, shellSpawn.rotation);
Rigidbody srb = shell.GetComponent<Rigidbody> ();
// FIXME: Hardcode.
srb.AddForce (shellSpawn.forward * Random.Range (1, 3), ForceMode.Impulse);
}
This get’s called when the player hit’s the Fire1 button. Here’s that code…
if (aiming) {
if (Input.GetButtonDown ("Fire1")) {
FireWeapon (new Ray(cameraRig.mainCamera.transform.position, cameraRig.mainCamera.transform.forward));
}
}
The FireWeapon function calls to the weapon and tells it to call the Fire() function, which then spawns the prefabs.
The problem is impossible for me to figure out and here’s a picture showing the setup:
And as you can see the transform is a child.
And in another script I have the spine rotating in late update:
Ray aimRay = new Ray(cameraRig.mainCamera.transform.position, cameraRig.mainCamera.transform.forward);
Vector3 lookPos = aimRay.GetPoint (50);
spine.LookAt(lookPos);
spine.Rotate (spineOffset, Space.Self);
Debug.Log (currentWeapon.transform.position);
But when the object spawns it spawns at the position that the gun is when im not aiming. even though I look down (it will spawn as if I’m looking straight forward)
I really hope you guys can help me.