- Home /
Question by
hellojbb1234 · Jan 12, 2017 at 08:05 AM ·
instantiatelocalposition
Why is this spawning the bullets in the center of the game world?
It is spawning it in the center of the world not where the position the weapon is. Also how do I make this into an actual gun.
public void FireStuff(GameObject prefab){
GameObject FatBut = prefab;
if (Timer >= TimeEnd) {
for (int i = 0; i < Bullets; i++) {
Vector3 firingPoint = new Vector3 (FiringPoints [i].localPosition.x, FiringPoints [i].localPosition.y, FiringPoints [i].localPosition.z);
Instantiate (FatBut, firingPoint, transform.rotation);
}
Timer = 0;
}
}
}
Comment
Answer by tanoshimi · Jan 12, 2017 at 08:12 AM
Probably because you're using the local position of the diring point (relative to whatever its parent is). You should use the position instead:
Vector3 firingPoint = new Vector3 (FiringPoints [i].position.x, FiringPoints [i].position.y, FiringPoints [i].position.z);
or, more simply:
Vector3 firingPoint = FiringPoints[i].position;
Your answer
Follow this Question
Related Questions
Help with firing projectiles out of turret 1 Answer
Help spawning an object relative to the local Z axis of an object 0 Answers
Checking if object intersects? 1 Answer
GameObject position and localPosition not changing in hiearchy, only in script. 0 Answers
How use local position of prefab for my instantiate ? 1 Answer