// Update is called once per frame void Update() { //transform.Rotate (v, h, 0); if(target == null) { GameObject lara = GameObject.Find("Lara"); if(lara!=null) { target = lara.transform; } else { Debug.Log("ThirdPersonCam: Target Not Found!"); return; } } if(!binit) { transform.position = target.position + (target.position - transform.position).normalized * 2048; anim = target.GetComponent<LaraStatePlayer>(); binit = true; } //Vector3 forward = target.forward; if(anim!=null && anim.OnAir) { //camrot += Input.GetAxis("Mouse X") * 10.0f; forward = Quaternion.Euler(0, camrot,0) * Vector3.forward; //camera.fieldOfView = Mathf.Lerp (camera.fieldOfView, fieldofview * 1.2f, Time.deltaTime * 5.0f); } else { forward = target.forward; //position = new Vector3(target.position.x, target.position.y + 700, target.position.z); //distance = (position - transform.position).magnitude; camrot = transform.eulerAngles.y; //camera.fieldOfView = Mathf.Lerp (camera.fieldOfView, fieldofview , Time.deltaTime * 10.0f); } RaycastHit hit = new RaycastHit(); if(Physics.Raycast(target.position, -forward, out hit,1500)) { distance = hit.distance; } else { distance = 1500; } if(anim!=null && anim.OnAir) { /*transform.position = position - forward * distance; forward = (target.position - transform.position).normalized; transform.forward = Vector3.Lerp(transform.forward ,forward,Time.deltaTime * 0.5f);*/ transform.forward = Vector3.Lerp(transform.forward , target.forward,Time.deltaTime * 5.0f); Vector3 pos = target.position - forward * distance; transform.position = Vector3.Lerp(transform.position,new Vector3(pos.x,pos.y + 700, pos.z),Time.deltaTime * 2.0f); //Debug.Log(camrot); } else { lookup += mouse_dy * 0.01f; mouse_dy = 0; transform.forward = Vector3.Lerp(transform.forward , target.forward + Vector3.up * lookup,Time.deltaTime * 5.0f) ; Vector3 pos = target.position - forward * distance; transform.position = Vector3.Lerp(transform.position,new Vector3(pos.x,pos.y + 700, pos.z),Time.deltaTime * 2.0f); } }
// Update is called once per frame void Update() { //transform.Rotate (v, h, 0); if (target == null) { GameObject lara = GameObject.Find("Lara"); if (lara != null) { target = lara.transform; target_hip = lara.transform.Find("objPart:0"); } else { Debug.Log("ThirdPersonCam: Target Not Found!"); return; } } if (!binit) { m_Transform.position = target.position + (target.position - m_Transform.position).normalized * 2048 * Settings.SceneScaling; anim = target.GetComponent <LaraStatePlayer>(); player = target.GetComponent <Player>(); binit = true; } //Vector3 forward = target.forward; if (anim != null && anim.OnAir) { //camrot += Input.GetAxis("Mouse X") * 10.0f; forward = Quaternion.Euler(0, camrot, 0) * Vector3.forward; //camera.fieldOfView = Mathf.Lerp (camera.fieldOfView, fieldofview * 1.2f, Time.deltaTime * 5.0f); } else { forward = target.forward; //position = new Vector3(target.position.x, target.position.y + 700, target.position.z); //distance = (position - transform.position).magnitude; camrot = transform.eulerAngles.y; //camera.fieldOfView = Mathf.Lerp (camera.fieldOfView, fieldofview , Time.deltaTime * 10.0f); } RaycastHit hit = new RaycastHit(); if (Physics.Raycast(target.position, -forward, out hit, 1500 * Settings.SceneScaling)) { distance = hit.distance; } else { distance = 1500 * Settings.SceneScaling; } if (anim != null && anim.OnAir) { /*transform.position = position - forward * distance; * forward = (target.position - transform.position).normalized; * transform.forward = Vector3.Lerp(transform.forward ,forward,Time.deltaTime * 0.5f);*/ m_Transform.forward = Vector3.Lerp(m_Transform.forward, target.forward, Time.deltaTime * 5.0f); Vector3 pos = target.position - forward * distance; m_Transform.position = Vector3.Lerp(m_Transform.position, new Vector3(pos.x, pos.y + 700 * Settings.SceneScaling, pos.z), Time.deltaTime * 2.0f); //Debug.Log(camrot); } else { if (anim.m_SwimState == SwimmingState.InDeepWater) { lookup = 0f; mouse_dy = 0; m_Transform.forward = Vector3.Lerp(m_Transform.forward, target.forward + Vector3.up * lookup, Time.deltaTime * 5.0f); Vector3 pos = target_hip.position - forward * distance; m_Transform.position = Vector3.Lerp(m_Transform.position, new Vector3(pos.x, pos.y + 128 * Settings.SceneScaling, pos.z), Time.deltaTime * 2.0f); } else { lookup += mouse_dy * 0.01f; mouse_dy = 0; m_Transform.forward = Vector3.Lerp(m_Transform.forward, target.forward + Vector3.up * lookup, Time.deltaTime * 5.0f); Vector3 pos = target_hip.position - forward * distance; m_Transform.position = Vector3.Lerp(m_Transform.position, new Vector3(pos.x, pos.y + 400 * Settings.SceneScaling, pos.z), Time.deltaTime * 2.0f); } } }
int m_bPlayerInstanceCount = 0; //flag to disable multiple player instances void InitialiseInstance(Parser.Tr2Item tr2item) { GameObject go = tr2item.UnityObject; go.name += " " + tr2item.ObjectID; if (tr2item.ObjectID == 0) { if (m_bPlayerInstanceCount == 1) { GameObject.Destroy(tr2item.UnityObject); return; } //playable character found! m_Player = go; m_Player.layer = UnityLayer.Player; m_PrevPlayPos = m_Player.transform.position; m_Player.transform.parent = m_LevelRoot; if (m_leveldata.Camera != null) { m_leveldata.Camera.target = m_Player.transform; } LaraStatePlayer stateplayer = m_Player.AddComponent <LaraStatePlayer>(); stateplayer.tranimations = m_DynamicPrefabs[0].AnimClips; m_Player.name = "Lara"; GameObject FlashLight = new GameObject("Fire Torch"); FlashLight.AddComponent <FlashLightStatePlayer>(); Light lt = FlashLight.AddComponent <Light>(); lt.type = LightType.Spot; lt.range = 5; lt.spotAngle = 70; lt.intensity = 5; FlashLight.transform.parent = m_Player.transform.Find("objPart:0");//.Find("objPart:7").Find("objPart:14"); FlashLight.transform.position = FlashLight.transform.parent.position; FlashLight.transform.forward = FlashLight.transform.parent.forward; lt.enabled = false; Player player = go.AddComponent <Player>(); player.m_Tr2Item = tr2item; HealthMonitor healthmon = go.AddComponent <HealthMonitor>(); PlayerCollisionHandler playercollider = go.AddComponent <PlayerCollisionHandler>(); //Initialise Current Active Room for player player.m_AnimStatePlayer = stateplayer; player.m_Room = SetRoomForPlayer(); if (player.m_Room != null) { Debug.Log("Player Rooms: " + player.m_Room.name); player.SetSwimState(player.m_Room); } AICondition.SetActive(m_Player, true); //set every game object under player as player Transform[] objs = m_Player.GetComponentsInChildren <Transform>(); foreach (Transform t in objs) { t.gameObject.layer = UnityLayer.Player; } //Add Charecter light GameObject LaraLight = new GameObject("Lara Light"); Light light = LaraLight.AddComponent <Light>(); light.transform.position = m_Player.transform.position; light.type = LightType.Directional; light.transform.forward = Vector3.Reflect(Vector3.one, -Vector3.up); light.transform.parent = m_Player.transform; light.cullingMask = MaskedLayer.Player; light.intensity = 0.3f; light.gameObject.AddComponent <LaraLightStatePlayer>(); m_bPlayerInstanceCount = 1; } //check if we have any custom behabiour script for object else if (m_OnAttachBehabiourScript != null && !m_OnAttachBehabiourScript(tr2item.UnityObject, tr2item.ObjectID, m_Player, tr2item)) { go.AddComponent <DefaultStatePlayer>(); // user did not attached any custom behabiour. so use default one AICondition.SetActive(go, true); //Added default activation state active } }
// Update is called once per frame void Update() { if((m_PrevPlayPos - m_Transform.position).sqrMagnitude > 2500) { m_DistancedCrossed += (m_Transform.position - m_PrevPlayPos).magnitude /1024.0f; OnGUIUpdate(new Rect(0,Screen.height - 25,Screen.width,100), "" + m_DistancedCrossed.ToString("f2")); m_Health -= m_DistancedCrossed * 0.00005f; OnGUIPlayerHealth(new Rect(0, 25,Screen.width,100), "" + m_Health.ToString("f2")); PositionChanged( m_Transform.position); m_PrevPlayPos = m_Transform.position; } //m_Room.DebugRoomSurface(facing_edeges); if(m_AnimStatePlayer == null) { m_AnimStatePlayer = GetComponent<LaraStatePlayer>(); //m_AnimStatePlayer.enabled = true; } InputUpdate(); //Update locomotion physics; if(!m_bJumping && !m_bPullingUp && !m_bWalkingUp && !m_bStandingUp) { if(m_bFreeFall) { transform.position = physics.UpdateFreeFall(Time.time - m_FreeFallStartTime); //m_bFreeFall = (m_GroundHeight > transform.position.y) ; if(m_GroundHeight > transform.position.y) { m_bFreeFall = false; transform.position = new Vector3(transform.position.x,m_GroundHeight,transform.position.z); } } else // simple height fixing { float h = Mathf.Lerp(transform.position.y ,m_GroundHeight, Time.deltaTime * 10.0f);// + 0.1f; transform.position = new Vector3(transform.position.x,h,transform.position.z); } } if(m_bJumping) { transform.position = physics.UpdateJump(Time.time - m_JumpStartTime); } if(m_bPullingUp) { OnPullingUp(); } if(m_bStandingUp) { OnStandingUp(); } if(m_bWalkingUp) { OnWalkingUp(); } }