void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { if (!PlayerRef && Managers.Game.PlayerPrefab) { PlayerRef = Managers.Game.PlayerPrefab; } if (PlayerRef != null) { PlayerCamera = PlayerRef.GetComponent <CameraTargetAttributes>(); } if (OneShot && !Managers.Dialog.IsInConversation()) { OneShot = false; Input.ResetInputAxes(); if (oneShotId != null) { //if (PlayerCamera) //if (zoom != PlayerCamera.distanceModifier) oldZoom = PlayerCamera.distanceModifier; isTalking = true; soundSource = Managers.Audio.Play(soundChat, gameObject.transform, 3f, 2); Managers.Dialog.StartConversation(oneShotId); } else { Debug.Log("Conversation ID not assigned"); } } } }
public IEnumerator ShowSneak(Vector3 startPosition) { // Start the cutscene CharacterInput input = GetComponent <CharacterInput>(); input.UpdateInputMethod = null; GameManager.IsPlayingCutscene = true; GameManager.MainCamera.Target = transform; // Start moving left transform.position = startPosition; input.Horizontal = 0.4f; yield return(new WaitForSeconds(1.0f)); // Zoom in on Babybot GameManager.MainCamera.CinematicOverride = true; EnemyAI babyBot = null; foreach (EnemyAI ai in GameManager.AI.Enemies) { if (ai.CharAnimator.EnemyType == EnemySaveState.EnemyType.Enemy_BabyBot) { babyBot = ai; } } GameManager.MainCamera.Target = babyBot.transform; GameManager.MainCamera.CinematicOverride = false; yield return(new WaitForSeconds(1.5f)); // Go back to the runner CameraTargetAttributes camAtt = gameObject.AddComponent <CameraTargetAttributes>(); GameManager.MainCamera.Target = transform; yield return(new WaitForSeconds(1.5f)); Destroy(camAtt); // End the cutscene GameManager.MainCamera.Target = GameManager.Player.transform; GameManager.IsPlayingCutscene = false; gameObject.SetActive(false); }
// Based on the camera attributes and the target's special camera attributes, find out where the // camera should move to. Vector3 GetGoalPosition() { // If there is no target, don't move the camera. So return the camera's current position as the goal position. if (!target) { return(transform.position); } // find camera target attributes if possible, if not use the defaults CameraTargetAttributes cameraTargetAttributes = target.GetComponent <CameraTargetAttributes>(); float heightOffset = cameraTargetAttributes ? cameraTargetAttributes.heightOffset : 0.0f; float distanceModifier = cameraTargetAttributes ? cameraTargetAttributes.distanceModifier : 1.0f; float velocityLookAhead = cameraTargetAttributes ? cameraTargetAttributes.velocityLookAhead : 0.0f; Vector2 maxLookAhead = cameraTargetAttributes ? cameraTargetAttributes.maxLookAhead : new Vector2(0.0f, 0.0f); // First do a rough goalPosition that simply follows the target at a certain relative height and distance. Vector3 goalPosition = target.position + new Vector3(0, heightOffset, -distance * distanceModifier); // Next, we refine our goalPosition by taking into account our target's current velocity. // This will make the camera slightly look ahead to wherever the character is going. // If we find a Rigidbody on the target, that means we can access a velocity! Rigidbody targetRigidbody = target.GetComponent <Rigidbody>(); Vector3 targetVelocity = targetRigidbody ? targetRigidbody.velocity : Vector3.zero; // Here we estimate what the target's position will be in velocityLookAhead seconds. Vector3 lookAhead = targetVelocity * velocityLookAhead; // Clamp the values to something sane, could be more dynamic but good in practice lookAhead.x = Mathf.Clamp(lookAhead.x, -maxLookAhead.x, maxLookAhead.x); lookAhead.y = Mathf.Clamp(lookAhead.y, -maxLookAhead.y, maxLookAhead.y); // Clear z adjustement as we are only concerned about looking ahead in 2d lookAhead.z = 0.0f; // Now add in our lookAhead calculation. Our camera following is now a bit better! goalPosition += lookAhead; // Send back our spiffily calculated goalPosition back to the caller! return(goalPosition); }
void Start() { if (!PlayerRef && Managers.Game.PlayerPrefab) { PlayerRef = Managers.Game.PlayerPrefab; } if (PlayerRef != null) { PlayerCamera = PlayerRef.GetComponent <CameraTargetAttributes>(); } if (ConversationFile != null) { Managers.Dialog.Init(ConversationFile); } else { Debug.Log("Conversation file XML not assigned"); return; } //enabled = false; }
public Vector3 GetGoalPosition() { if (!target) { return(base.transform.position); } float num = 1f; float d = 0f; Vector2 vector = new Vector2(0f, 20f); CameraTargetAttributes exists = target.GetComponent("CameraTargetAttributes") as CameraTargetAttributes; if ((bool)exists) { num = CameraTargetAttributes.distanceModifier; d = CameraTargetAttributes.velocityLookAhead; vector = CameraTargetAttributes.maxLookAhead; } Vector3 vector2 = target.position + new Vector3(0f, 0f, (0f - distance) * num); Vector3 a = Vector3.zero; Rigidbody rigidbody = target.GetComponent("Rigidbody") as Rigidbody; if ((bool)rigidbody) { a = rigidbody.velocity; } Vector3 vector3 = a * d; vector3.x = Mathf.Clamp(vector3.x, 0f - vector.x, vector.x); vector3.y = Mathf.Clamp(vector3.y, 0f - vector.y, vector.y); vector3.z = 0f; vector2 += vector3; Vector3 zero = Vector3.zero; Vector3 position = base.transform.position; if (gs.myPlayer != null) { Player player = gs.myPlayer.GetComponent("Player") as Player; if (player != null && !player.myState.amDoing(64) && player.mAmReady && !GamePlay.mPauseScreenActive && !player.bDisableControl) { float min = 0f; float min2 = 0f; float max = Screen.width; float max2 = Screen.height; if (gs != null && gs.mHUD != null) { min = gs.mHUD.leftEdge; max = gs.mHUD.rightEdge; min2 = gs.mHUD.topEdge; max2 = gs.mHUD.bottomEdge; } Vector3 mousePosition = Input.mousePosition; float x = Mathf.Clamp(mousePosition.x, min, max); Vector3 mousePosition2 = Input.mousePosition; float y = Mathf.Clamp(mousePosition2.y, min2, max2); Vector3 position2 = target.transform.position; float z = position2.z; Vector3 position3 = Camera.main.transform.position; float num2 = z - position3.z; Vector3 a2 = Camera.main.ScreenToWorldPoint(new Vector3(x, y, Camera.main.nearClipPlane + num2)); Vector3 vector4 = a2 - target.transform.position; float num3 = vector4.magnitude * 0.5f; if (player.mAmSniping) { num3 *= 2f; num3 = Mathf.Clamp(num3, num3, 500f); } else { num3 = Mathf.Clamp(num3, num3, 30f); } vector4.Normalize(); vector4.x *= num3; vector4.y *= num3; vector4.z = 0f; vector2 += vector4; } } base.transform.position = vector2; Vector3 vector5 = GetComponent <Camera>().WorldToViewportPoint(target.position); Vector3 vector6 = GetComponent <Camera>().ViewportToWorldPoint(new Vector3(1f, 1f, vector5.z)); zero.x = Mathf.Min(levelBounds.xMax - vector6.x, 0f); zero.y = Mathf.Min(levelBounds.yMax - vector6.y, 0f); vector2 += zero; base.transform.position = vector2; Vector3 vector7 = GetComponent <Camera>().ViewportToWorldPoint(new Vector3(0f, 0f, vector5.z)); zero.x = Mathf.Max(levelBounds.xMin - vector7.x, 0f); zero.y = Mathf.Max(levelBounds.yMin - vector7.y, 0f); vector2 += zero; base.transform.position = position; return(vector2); }
// Based on the camera attributes and the target's special camera attributes, find out where the // camera should move to. public Vector3 GetGoalPosition() { // If there is no target, don't move the camera. So return the camera's current position as the goal position. if (!target) { return(transform.position); } // Our camera script can take attributes from the target. If there are no attributes attached, we have // the following defaults. // How high in world space should the camera look above the target? float heightOffset = 0.0f; // How much should we zoom the camera based on this target? float distanceModifier = 1.0f; // By default, we won't account for any target velocity in our calculations; float velocityLookAhead = 0.0f; Vector2 maxLookAhead = new Vector2(0.0f, 0.0f); // Look for CameraTargetAttributes in our target. CameraTargetAttributes cameraTargetAttributes = (CameraTargetAttributes)target.GetComponent("CameraTargetAttributes"); // If our target has special attributes, use these instead of our above defaults. if (cameraTargetAttributes) { heightOffset = cameraTargetAttributes.heightOffset; distanceModifier = cameraTargetAttributes.distanceModifier; velocityLookAhead = cameraTargetAttributes.velocityLookAhead; maxLookAhead = cameraTargetAttributes.maxLookAhead; } // First do a rough goalPosition that simply follows the target at a certain relative height and distance. Vector3 goalPosition = target.position + new Vector3(0, heightOffset, -distance * distanceModifier); // Next, we refine our goalPosition by taking into account our target's current velocity. // This will make the camera slightly look ahead to wherever the character is going. // First assume there is no velocity. // This is so if the camera's target is not a Rigidbody, it won't do any look-ahead calculations because everything will be zero. Vector3 targetVelocity = Vector3.zero; // If we find a Rigidbody on the target, that means we can access a velocity! targetRigidbody = (Rigidbody)target.GetComponent("Rigidbody"); if (targetRigidbody) { targetVelocity = targetRigidbody.velocity; } // If we find a PlatformerController on the target, we can access a velocity from that! PlatformerController targetPlatformerController = (PlatformerController)(target.GetComponent("PlatformerController")); if (targetPlatformerController) { targetVelocity = targetPlatformerController.GetVelocity(); } // If you've had a physics class, you may recall an equation similar to: position = velocity * time; // Here we estimate what the target's position will be in velocityLookAhead seconds. Vector3 lookAhead = targetVelocity * velocityLookAhead; // We clamp the lookAhead vector to some sane values so that the target doesn't go offscreen. // This calculation could be more advanced (lengthy), taking into account the target's viewport position, // but this works pretty well in practice. lookAhead.x = Mathf.Clamp(lookAhead.x, -maxLookAhead.x, maxLookAhead.x); lookAhead.y = Mathf.Clamp(lookAhead.y, -maxLookAhead.y, maxLookAhead.y); // We never want to take z velocity into account as this is 2D. Just make sure it's zero. lookAhead.z = 0.0f; // Now add in our lookAhead calculation. Our camera following is now a bit better! goalPosition += lookAhead; // To put the icing on the cake, we will make so the positions beyond the level boundaries // are never seen. This gives your level a great contained feeling, with a definite beginning // and ending. Vector3 clampOffset = Vector3.zero; // Temporarily set the camera to the goal position so we can test positions for clamping. // But first, save the previous position. Vector3 cameraPositionSave = transform.position; transform.position = goalPosition; // Get the target position in viewport space. Viewport space is relative to the camera. // The bottom left is (0,0) and the upper right is (1,1) // @TODO Viewport space changing in Unity 2.0? Vector3 targetViewportPosition = GetComponent <Camera>().WorldToViewportPoint(target.position); // First clamp to the right and top. After this we will clamp to the bottom and left, so it will override this // clamping if it needs to. This only occurs if your level is really small so that the camera sees more than // the entire level at once. // What is the world position of the very upper right corner of the camera? Vector3 upperRightCameraInWorld = GetComponent <Camera>().ViewportToWorldPoint(new Vector3(1.0f, 1.0f, targetViewportPosition.z)); // Find out how far outside the world the camera is right now. clampOffset.x = Mathf.Min(levelBounds.xMax - upperRightCameraInWorld.x, 0.0f); clampOffset.y = Mathf.Min((levelBounds.yMax - upperRightCameraInWorld.y), 0.0f); // Now we apply our clamping to our goalPosition. Now our camera won't go past the right and top boundaries of the level! goalPosition += clampOffset; // Now we do basically the same thing, except clamp to the lower left of the level. This will override any previous clamping // if the level is really small. That way you'll for sure never see past the lower-left of the level, but if the camera is // zoomed out too far for the level size, you will see past the right or top of the level. transform.position = goalPosition; Vector3 lowerLeftCameraInWorld = GetComponent <Camera>().ViewportToWorldPoint(new Vector3(0.0f, 0.0f, targetViewportPosition.z)); // Find out how far outside the world the camera is right now. clampOffset.x = Mathf.Max((levelBounds.xMin - lowerLeftCameraInWorld.x), 0.0f); clampOffset.y = Mathf.Max((levelBounds.yMin - lowerLeftCameraInWorld.y), 0.0f); // Now we apply our clamping to our goalPosition once again. Now our camera won't go past the left and bottom boundaries of the level! goalPosition += clampOffset; // Now that we're done calling functions on the camera, we can set the position back to the saved position; transform.position = cameraPositionSave; // Send back our spiffily calculated goalPosition back to the caller! return(goalPosition); }
} // con esto llamamos al Conversation Manager desde Statement.cpp ////////////////////////////////////////////////////////////// public void Update() //: IEnumerator { if (CamTarget == null && Managers.Game.PlayerPrefab) { CamTarget = Managers.Game.PlayerPrefab.GetComponent <CameraTargetAttributes>() as CameraTargetAttributes; } if (IsInConversation()) { //if (!mbConversationState) return; if (CamTarget.Offset.x > 0) // Check Player Position and Id { miChatDirection = System.Convert.ToByte(miChatDirection != 0); // the Player is on left side } else { miChatDirection = System.Convert.ToByte(miChatDirection == 0); // else the Player is on right } ComicCoord = new Rect(.5f * miChatDirection, 0, (miChatDirection > 0 ? -.5f : .5f), .25f); if (!Managers.Game.IsPaused) { if (mpCurrentConversationNode != null) { switch (mpCurrentConversationNode.meType) { case eConversationNodeType.eNormalTalk: // Enum 0; Nodo activo de tipo eNormalTalk if (mpCurrentConversationNode != mpPreviousConversationNode) { miCharIndex += System.Convert.ToByte(Time.frameCount % CharShowDelay == 0); // Increment each 10 Secs of Frames (speed) if (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Jump") || Input.GetKeyDown("return")) { miCharIndex = 0; mpPreviousConversationNode = mpCurrentConversationNode; } break; } mfMessageTime -= Time.deltaTime * .1f; // Decrease the message time if ((mfMessageTime <= 0.0f) || Input.GetButtonDown("Fire1") || Input.GetKeyDown("return")) { NextMessage(0); //Need to continue with the next message or node } break; case eConversationNodeType.eChooseTalk: // Enum 1; Nodo activo de tipo eChooseTalk if (Managers.Game.InputUp && (muiChooseOption > 0)) { muiChooseOption--; } if (Managers.Game.InputDown && (muiChooseOption < (mpCurrentConversationNode.mChildren.Count - 1))) { muiChooseOption++; } if (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Jump") || Input.GetKeyDown("return")) { if (miChooseIndex < mpCurrentConversationNode.mChildren.Count) { miCharIndex = 0; miChooseIndex = mpCurrentConversationNode.mChildren.Count; break; } miCharIndex = 0; miChooseIndex = 0; mpPreviousConversationNode = mpCurrentConversationNode; NextMessage(muiChooseOption); } break; default: // Enum 2; Nodo activo de tipo eEndConversation mpCurrentConversationNode = null; break; } } else { mbConversationState = false; // If we have a null mpCurrentConversationNode then it´s the end } } } }
Vector3 GetGoalPosition() // find out where the camera should move to, Based on camera and target's attributes { if (!target) { return(thisTransform.position); // If there isn't target, don't move the camera & return current position. } // Our camera script can take attributes from the target. // If there are no attributes attached, we have the following defaults. float heightOffset = 0; // How high in world space should the camera look above the target? float widthOffset = 0; float distanceModifier = 2.5f; // How much should we zoom the camera based on this target? float velocityLookAhead = 0; // By default, we won't account for any target velocity in calculations; Vector2 maxLookAhead = new Vector2(0, 0); // Look for CameraTargetAttributes in our target. CameraTargetAttributes cameraTargetAttributes = target.GetComponent <CameraTargetAttributes>(); if (cameraTargetAttributes) // If our target has special attributes, use these instead of our above defaults. { heightOffset = cameraTargetAttributes.Offset.y; widthOffset = cameraTargetAttributes.Offset.x; distanceModifier = cameraTargetAttributes.distanceModifier; velocityLookAhead = cameraTargetAttributes.velocityLookAhead; maxLookAhead = cameraTargetAttributes.maxLookAhead; } // First do a rough goalPosition that simply follows the target at a certain relative height and distance. Vector3 goalPosition = target.position + new Vector3(widthOffset, heightOffset, -2.5f); zoomFactor = -distance * distanceModifier; // some provisory fixes for ortogonal camera // Next, we refine our goalPosition by taking into account our target's current velocity. // This will make the camera slightly look ahead to wherever the character is going: Vector3 targetVelocity = Vector3.zero; // First assume there is no velocity. // in case camera's target isn't a Rigidbody, it won't do any look-ahead calculations because everything will be zero. var targetRigidbody = target.GetComponent <CharacterController>(); // If we find a Rigidbody on target.. if (targetRigidbody) { targetVelocity = targetRigidbody.velocity; // that means we can access at his velocity! } // If you've had a physics class, you may recall an equation similar to: position = velocity * time; Vector3 lookAhead = targetVelocity * velocityLookAhead; // target's position will be in velocityLookAhead seconds. lookAhead.x = Mathf.Clamp(lookAhead.x, -maxLookAhead.x, maxLookAhead.x); // clamp the vector to some input lookAhead.y = Mathf.Clamp(lookAhead.y, -maxLookAhead.y, maxLookAhead.y); // so the target doesn't go offscreen. lookAhead.z = 0; // We never want to take z velocity into account as this is 2D. Just keep it in zero. goalPosition += lookAhead; // Now add in our lookAhead calculation. Our camera following is now a bit better! // To put the icing on the cake, we will make so the positions beyond the level boundaries are never seen. Vector3 clampOffset = Vector3.zero; // This gives your level a great contained feeling, with a definite beginning and end. Vector3 cameraPositionSave = thisTransform.position; // But first, save the previous position. thisTransform.position = goalPosition; // Temporarily set camera to the goal position so we can test positions for clamping. // Get the target position in viewport space. Viewport space is relative to the camera. // bottom left is (0,0) and upper right is (1,1) Vector3 targetViewportPosition = camera.WorldToViewportPoint(target.position); // 1º clamp to the right & top. After this we will clamp to the bottom & left, so it will override this clamping // if it needs to. only in case that level is too smaller that camera sees more than the entire level at once. // What is the world position of the very upper right corner of the camera? Vector3 upperRightCameraInWorld = camera.ViewportToWorldPoint(new Vector3(1.0f, 1.0f, targetViewportPosition.z)); // Find out how far outside the world the camera is right now. clampOffset.x = Mathf.Min(levelBounds.xMax - upperRightCameraInWorld.x, 0.0f); clampOffset.y = Mathf.Min((levelBounds.yMax - upperRightCameraInWorld.y), 0.0f); // Now we apply our clamping to our goalPosition. Now our camera won't go past the right and top boundaries of the level! goalPosition += clampOffset; // Now we do basically the same thing, except clamp to the lower left of the level. This will override any previous clamping // if the level is really small. That way you'll for sure never see past the lower-left of the level, but if the camera is // zoomed out too far for the level size, you will see past the right or top of the level. thisTransform.position = goalPosition; Vector3 lowerLeftCameraInWorld = camera.ViewportToWorldPoint(new Vector3(0.0f, 0.0f, targetViewportPosition.z)); // Find out how far outside the world the camera is right now. clampOffset.x = Mathf.Max((levelBounds.xMin - lowerLeftCameraInWorld.x), 0.0f); clampOffset.y = Mathf.Max((levelBounds.yMin - lowerLeftCameraInWorld.y), 0.0f); // Now we apply our clamping to our goalPosition once again. Now our camera won't go past the left and bottom boundaries of the level! goalPosition += clampOffset; // Now that we're done calling functions on the camera, we can set the position back to the saved position; thisTransform.position = cameraPositionSave; // Send back our spiffily calculated goalPosition back to the caller! return(goalPosition); }