- Home /
Question by
$$anonymous$$ · Sep 11, 2018 at 07:37 AM ·
scripting probleminstantiatetransform.position
Instantiate object at specific distance from transform position?
I am attempting to instantiate a bullet at the end of a barrel (x = -2.4). How can i set the position once it's created?
Current code is this, shell is currently spawning at the origin of the barrel, not the end.
private void FireShell()
{
GameObject shellClone = Instantiate(Shell, Barrel.transform.position, Barrel.transform.rotation) as GameObject;
Rigidbody shellCloneRB = shellClone.AddComponent<Rigidbody>();
SphereCollider shellCloneSC = shellClone.AddComponent<SphereCollider>();
shellCloneSC.isTrigger = true;
shellCloneRB.AddRelativeForce(Vector3.left * power * );
Destroy(shellClone, 5);
}
Comment
Best Answer
Answer by RocketFriday · Sep 11, 2018 at 07:45 AM
Create an empty GameObject and parent it to the gun. Use its transform for position and rotation.
Your answer
Follow this Question
Related Questions
Why does my instatiate crashes editor? 1 Answer
I need to move a clone of a prefab to a specific position after it instantiates 1 Answer
transform of instantiated bullet via ui button press not following the player 0 Answers
prefab always instantiates at 0.0.0 1 Answer
I want to make a gun with 2 parts and follow their positions and scales 2 Answers