Hey, how could I instantiate an object in front of the player. I checked the reference for Instantiate and it can have a position in vector3. How could I simply spawn an object 5 units in front of my player? Thanks.
Simple do that:
public Vector3 playerPos;
public GameObject yourObject;
void Start(){
playerPos = yourPlayer.transform.position;
instantiate(yourObject, new Vector3(playerPos.transform.position.x + 5, playerPos.transform.position.y, playerPos.transform.position.z), Quaternion.identity);
}
Assuming 3D and by ‘in front’ you are referring to the side facing positive ‘z’ when rotation is (0,0,0):
Instantiate(prefab, transform.position + transform.forward * 5, Quaternion.Identity);