Question by
kuku37 · Jan 07, 2019 at 03:20 PM ·
positioninginstatiate
How do i instantiate an prefab in a certain position ?
i am trying to create a platformer and i want a spike to be instantiate infront and at the center of my player each time i press the b button instead of that the spike is instatiated from the head of my player.. any help ?
Comment
Best Answer
Answer by tormentoarmagedoom · Jan 07, 2019 at 03:40 PM
Good day.
You are using instantiate() in this form:
Instantiate (ObjectToInstantiate, PositionToInstantiate, RotationToInstantiate)
You are now Instantiating at "transform.position" So, you are instantiating at the position of the object that have this script attached to (i supose is the character)
You only need to change that transform.position to what you want.
Tip: You can write a vector with its components and "change some of them" like this:
Vector3 NewPosition = new Vector3(transfomr.position.x, transform.position.y+10, -5);
Instantiate (ObjectToInstantiate, NewPosition , RotationToInstantiate);
Bye