tel
New vMember
Posts: 16
|
Post by tel on Feb 23, 2020 14:22:33 GMT
Maybe I am missing something here (I usually am)
After death and respawn, the Player is now a clone, so that when it comes back the colliders that have, for example
private void OnTriggerEnter(Collider other)
{
if (other.transform == player)
do not work anymore. I can see ways around this, but what is the best solution.
|
|
|
Post by Invector on Feb 24, 2020 13:56:01 GMT
You should compare the tag instead of the transform
if(other.gameObject.CompareTag("Player"))
|
|
tel
New vMember
Posts: 16
|
Post by tel on Feb 24, 2020 16:32:46 GMT
Thanks, but that is not much help when I am doing CanSeePlayer(), which relies on being able to find the player quickly, because it is called often.
public bool CanSeePlayer() { Vector3 playerDirection = (player.position - character.position); RaycastHit hit; Physics.Raycast(character.position+new Vector3(0,0.5f,0), playerDirection, out hit, playerDirection.magnitude/*,LayerMask.NameToLayer("Player")*/); etc, etc. I guess that after spawning, I would like an event that the "new' character has been created, so that I could reset the player reference.
|
|
tel
New vMember
Posts: 16
|
Post by tel on Feb 26, 2020 21:29:46 GMT
The answer, which I found after some searching, is to take advantage of the fact that vGameController updates a currentPlayer field, so you can use
vGameController.instance.currentPlayer.transform.position
This gets set when the Player starts, and reset when the clone has been instantiated.
|
|