Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Switch camera to cloned object.

$
0
0
Hello again. I have a problem with my camera, it follows a player like a 3rd person camera, it is fine but when my player dies an instantiated ragdoll is cloned and player object is destroyed. So I want my camera follows that ragdoll. I got this so far: #pragma strict var target : Transform; var height : float; var distance : float; var shoulderView : float; private var targetPosition : Vector3; function Update(){ if(_playerHealth.playerDead){ var sf : _cameraScript = Camera.main.GetComponent(_cameraScript); sf.target = transform.Find("Ragdoll(Clone)"); } } function LateUpdate () { if(!_playerHealth.playerDead){ transform.LookAt(aimTarget); }else{ transform.LookAt(target); } targetPosition = target.position + target.right * shoulderView + target.up * height - target.forward * distance; transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * 30.0); } I've tried things like replacing target with another variable finding the clone with tag etc.. And I have the same error: NullReferenceException at targetPosition variable in LateUpdate. Thanks in advance.

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>