❔ How to use a GameObject's location as the location for Instantiate
Hi so I'm trying to make a projectile, and I want the spawn location to be relative to the location of the player. Thanks in advance!
3 Replies
'''Instantiate(gameobject, transform.position+offset, Quaternion.identity);'''
A vector3 named as offset is used to change the spawn position and the transform.position spawns the object at the position of the object on which the spawner script sits
You can create a variable for the Transform component of player and refer to it in your scipt
public Transform player;
Public GameObject prefab;
Publicn Vector3 offset;
Void Start(){
Instantiate(prefab, player.position+offset, Quaternion.identity);
}
oh awesome, thank you so much!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.