/// <summary> /// Activates the action on a single target /// </summary> /// <param name="rTarget">Target to activate on</param> protected void ActivateInstance(GameObject rTarget, Vector3 rPoint, Vector3 rForward) { float lPower = UnityEngine.Random.Range(MinPower, MaxPower); if (Invert) { lPower = -lPower; } // Push back the Motion Controller if we can ActorController lActorController = rTarget.GetComponent <ActorController>(); if (AddForce && lActorController != null) { Vector3 lMovement = rForward.normalized * (lPower * AddForceFactor); lActorController.AddImpulse(lMovement); } else { Rigidbody lRigidBody = rTarget.GetComponent <Rigidbody>(); if (lRigidBody != null) { // Compensate for the exaggerated force describe in Unity documentation lRigidBody.AddForceAtPosition(rForward.normalized * lPower * 0.01f, rPoint, ForceMode.Impulse); } } }
/// <summary> /// Called every frame so the driver can process input and /// update the actor controller. /// </summary> protected virtual void Update() { if (!_IsEnabled) { return; } if (mActorController == null) { return; } if (mInputSource == null || !mInputSource.IsEnabled) { return; } float lDeltaTime = TimeManager.SmoothedDeltaTime; // Rotate based on the mouse if (mInputSource.IsViewingActivated) { float lYaw = mInputSource.ViewX; Quaternion lRotation = Quaternion.Euler(0f, lYaw * mDegreesPer60FPSTick, 0f); mActorController.Rotate(lRotation); } // Move based on WASD Vector3 lInput = new Vector3(mInputSource.MovementX, 0f, mInputSource.MovementY); Vector3 lMovement = lInput * _MovementSpeed * lDeltaTime; if (lMovement.sqrMagnitude > 0f) { mActorController.RelativeMove(lMovement); } // Jump based on space if (mInputSource.IsJustPressed("Jump")) { if (mActorController.State.IsGrounded) { mActorController.AddImpulse(transform.up * _JumpForce); } } }
/// <summary> /// Called every frame so the driver can process input and /// update the actor controller. /// </summary> protected virtual void Update() { // Ensure we have everything we need if (mActorController == null) { return; } if (mInputSource == null || !mInputSource.IsEnabled) { return; } // Initialize some variables Vector3 lMovement = Vector3.zero; Quaternion lRotation = Quaternion.identity; // ----------------------------------------------------------------- // INPUT // ----------------------------------------------------------------- // This is the horizontal movement of the mouse or Xbox controller's right stick //float lYaw = mInputSource.ViewX; // This is the WASD buttons or Xbox controller's left stick Vector3 lInput = new Vector3(mInputSource.MovementX, 0f, mInputSource.MovementY); // ----------------------------------------------------------------- // ATTACH TO WALL // ----------------------------------------------------------------- if (mIsInToWall) { Vector3 lToWallHit = mToWallPoint - transform.position; float lToWallHitNormal = Vector3.Angle(mActorController._Transform.up, mToWallNormal); // Move to the target and ensure we orient ourselves to the wall if (lToWallHit.magnitude > 0.03f || lToWallHitNormal > 0.5f) { mActorController.SetTargetGroundNormal(mToWallNormal); lMovement = lToWallHit.normalized * Mathf.Min(MovementSpeed * Time.deltaTime, lToWallHit.magnitude); mActorController.Move(lMovement); } // Once we're there, clean up else { mIsInToWall = false; mToWallPoint = Vector3.zero; mToWallNormal = Vector3.zero; mActorController.MaxSlopeAngle = mSavedMaxSlopeAngle; mActorController.OrientToGroundSpeed = mSavedOrientToGroundSpeed; mActorController.SetTargetGroundNormal(Vector3.zero); // Disable gravity temporarily mActorController.IsGravityEnabled = true; mActorController.FixGroundPenetration = true; } } else { // ----------------------------------------------------------------- // ROTATE // ----------------------------------------------------------------- // Set the target based on the input. This works because we're looking down // the world's z-axis. if (lInput.x < 0f) { mTargetForward = Vector3.left; } else if (lInput.x > 0f) { mTargetForward = Vector3.right; } // If we have a target forward start rotating towards it and ignore input if (mTargetForward.sqrMagnitude > 0f) { // Determine how much we need to rotate to get to the target float lTargetAngle = Vector3Ext.SignedAngle(mActorController.Yaw.Forward(), mTargetForward); // If there is no difference, we can turn off the target if (lTargetAngle == 0f) { mTargetForward = Vector3.zero; } else { // Grab the actual rotation angle based on our speed. However, make sure we don't overshoot the // angle. So, we do this logic to truncate it if we're only a tiny bit off. float lRotationAngle = Mathf.Sign(lTargetAngle) * Mathf.Min(RotationSpeed * Time.deltaTime, Mathf.Abs(lTargetAngle)); // Since the rotate function deals with the actor's yaw, we just to a vector3.up (it's // relative to the actor regardless of his orientation/tilt lRotation = Quaternion.AngleAxis(lRotationAngle, Vector3.up); // Rotate. mActorController.Rotate(lRotation); } } // ----------------------------------------------------------------- // MOVE // ----------------------------------------------------------------- // We get the tilt so we can add this up/down direction to the camera input. This helps // characters to not run off ramps since they are moving how they are facing (ie down a ramp) // vs. simply forward (off the ramp) Quaternion lTilt = QuaternionExt.FromToRotation(Vector3.up, mActorController._Transform.up); // Move based on WASD we add the tilt lMovement = lTilt * lInput * MovementSpeed * Time.deltaTime; mActorController.Move(lMovement); // ----------------------------------------------------------------- // JUMP // ----------------------------------------------------------------- // Only jump if the button is pressed and we're on the ground if (mInputSource.IsJustPressed("Jump")) { if (mActorController.State.IsGrounded) { mActorController.AddImpulse(mActorController._Transform.up * JumpForce); } } // ----------------------------------------------------------------- // TEST FOR WALL // ----------------------------------------------------------------- RaycastHit lWallHitInfo; if (TestForWallCollision(lMovement, out lWallHitInfo) || TestForWallAt90DegreeDrop(lMovement, out lWallHitInfo)) { // Save the tilt values mIsInToWall = true; mToWallPoint = lWallHitInfo.point; mToWallNormal = lWallHitInfo.normal; // Save and reset some AC values that will help us to tilt mSavedOrientToGroundSpeed = mActorController.OrientToGroundSpeed; mActorController.OrientToGroundSpeed = 0.75f; mSavedMaxSlopeAngle = mActorController.MaxSlopeAngle; mActorController.MaxSlopeAngle = 0f; // Disable gravity temporarily mActorController.IsGravityEnabled = false; mActorController.FixGroundPenetration = false; } } }
/// <summary> /// Activates a single target by running the links for that target /// </summary> /// <param name="rTarget"></param> protected virtual bool ActivateInstance(GameObject rTarget, object rData) { if (rTarget == null) { return(true); } // We calculate the value each time in case the ApplyForceSpherical is called // again while we're running (it shouldn't, but just in case) Transform lCenterTransform = null; Vector3 lCenterPosition = Vector3.zero; GetBestPosition(AnchorTypeIndex, null, _Spell.Data, AnchorOffset, out lCenterTransform, out lCenterPosition); float lPower = UnityEngine.Random.Range(MinPower, MaxPower); if (Invert) { lPower = -lPower; } // Push back the Motion Controller if we can ActorController lActorController = rTarget.GetComponent <ActorController>(); //MotionController lMotionController = rTarget.GetComponent<MotionController>(); if (AddForce && lActorController != null) { Vector3 lMovement = ((rTarget.transform.position + _TargetOffset) - lCenterPosition).normalized; lMovement = lMovement * (lPower * AddForceFactor); lActorController.AddImpulse(lMovement); } //else if (SendPushBackMessage && lMotionController != null) //{ // Vector3 lMovement = ((rTarget.transform.position + _TargetOffset) - lCenterPosition).normalized; // lMovement = lMovement * (lPower * PushBackFactor); // Navigation.NavigationMessage lMessage = Navigation.NavigationMessage.Allocate(); // lMessage.ID = Navigation.NavigationMessage.MSG_NAVIGATE_PUSHED_BACK; // lMessage.Data = lMovement; // lMotionController.SendMessage(lMessage); // lMessage.Release(); // if (_Spell.ShowDebug) // { // Graphics.GraphicsManager.DrawSphere(lCenterPosition, 0.2f, Color.blue); // Graphics.GraphicsManager.DrawLine(lCenterPosition, lCenterPosition + lMovement, Color.blue, null, 5f); // } //} else { // Use the RigidBody if we have it Rigidbody lRigidBody = rTarget.GetComponent <Rigidbody>(); if (lRigidBody != null && !lRigidBody.isKinematic) { float lLift = UnityEngine.Random.Range(MinLift, MaxLift); lRigidBody.AddExplosionForce(lPower, lCenterPosition, Radius, -lLift); } //else //{ // // Modify Movement if we should // ActorCore lActorCore = rTarget.GetComponent<ActorCore>(); // if (SendModifyMovement && lActorCore != null) // { // string lEffectName = "AFS"; // LifeCores.ForceMovement lEffect = lActorCore.GetActiveEffectFromName<LifeCores.ForceMovement>(lEffectName); // if (lEffect != null) // { // lEffect.Age = 0f; // } // else // { // Vector3 lMovement = ((rTarget.transform.position + _TargetOffset) - lCenterPosition).normalized; // lMovement = lMovement * (lPower * ModifyMovementFactor); // lEffect = LifeCores.ForceMovement.Allocate(); // lEffect.Name = lEffectName; // lEffect.SourceID = mNode.ID; // lEffect.ActorCore = lActorCore; // lEffect.Movement = lMovement; // lEffect.ReduceMovementOverTime = true; // lEffect.Activate(0f, 1f); // lActorCore.ActiveEffects.Add(lEffect); // } // } //} } return(true); }
/// <summary> /// Called every frame so the driver can process input and /// update the actor controller. /// </summary> protected virtual void Update() { // Ensure we have everything we need if (mActorController == null) { return; } if (mInputSource == null || !mInputSource.IsEnabled) { return; } // Initialize some variables Vector3 lMovement = Vector3.zero; Quaternion lRotation = Quaternion.identity; // ----------------------------------------------------------------- // INPUT // ----------------------------------------------------------------- // This is the horizontal movement of the mouse or Xbox controller's right stick float lYaw = mInputSource.ViewX; // This is the WASD buttons or Xbox controller's left stick Vector3 lInput = new Vector3(mInputSource.MovementX, 0f, mInputSource.MovementY); // ----------------------------------------------------------------- // ROTATE // ----------------------------------------------------------------- // If the input source says we can, rotate based on the yaw. if (mInputSource.IsViewingActivated) { // The input from the mouse already takes the frame rate into account. By doing // the multiplication here, we keep the rotation consistant across frame rates. lRotation = Quaternion.Euler(0f, lYaw * mDegreesPer60FPSTick, 0f); // Rotate our actor mActorController.Rotate(lRotation); } // ----------------------------------------------------------------- // MOVE // ----------------------------------------------------------------- // We get the tilt so we can add this up/down direction to the camera input. This helps // characters to not run off ramps since they are moving how they are facing (ie down a ramp) // vs. simply forward (off the ramp) Quaternion lTilt = QuaternionExt.FromToRotation(Vector3.up, mActorController._Transform.up); // Move based on WASD we add the tilt lMovement = lTilt * lInput * MovementSpeed * Time.deltaTime; mActorController.Move(lMovement); // ----------------------------------------------------------------- // JUMP // ----------------------------------------------------------------- // Only jump if the button is pressed and we're on the ground if (mInputSource.IsJustPressed("Jump")) { if (mActorController.State.IsGrounded) { mActorController.AddImpulse(mActorController._Transform.up * JumpForce); } } }
/// <summary> /// Called every frame so the driver can process input and /// update the actor controller. /// </summary> protected virtual void Update() { // Ensure we have everything we need if (mActorController == null) { return; } if (mInputSource == null || !mInputSource.IsEnabled) { return; } // Initialize some variables Vector3 lMovement = Vector3.zero; Quaternion lRotation = Quaternion.identity; // ----------------------------------------------------------------- // INPUT // ----------------------------------------------------------------- // This is the horizontal movement of the mouse or Xbox controller's right stick //float lYaw = mInputSource.ViewX; // This is the WASD buttons or Xbox controller's left stick Vector3 lInput = new Vector3(mInputSource.MovementX, 0f, mInputSource.MovementY); // ----------------------------------------------------------------- // ROTATE // ----------------------------------------------------------------- // Set the target based on the input. This works because we're looking down // the world's z-axis. if (lInput.x < 0f) { mTargetForward = Vector3.left; } else if (lInput.x > 0f) { mTargetForward = Vector3.right; } // If we have a target forward start rotating towards it and ignore input if (mTargetForward.sqrMagnitude > 0f) { // Determine how much we need to rotate to get to the target float lTargetAngle = Vector3Ext.SignedAngle(mActorController.Yaw.Forward(), mTargetForward); // If there is no difference, we can turn off the target if (lTargetAngle == 0f) { mTargetForward = Vector3.zero; } else { // Grab the actual rotation angle based on our speed. However, make sure we don't overshoot the // angle. So, we do this logic to truncate it if we're only a tiny bit off. float lRotationAngle = Mathf.Sign(lTargetAngle) * Mathf.Min(RotationSpeed * Time.deltaTime, Mathf.Abs(lTargetAngle)); // Since the rotate function deals with the actor's yaw, we just to a vector3.up (it's // relative to the actor regardless of his orientation/tilt lRotation = Quaternion.AngleAxis(lRotationAngle, Vector3.up); // Rotate. mActorController.Rotate(lRotation); } } // ----------------------------------------------------------------- // MOVE // ----------------------------------------------------------------- // We get the tilt so we can add this up/down direction to the camera input. This helps // characters to not run off ramps since they are moving how they are facing (ie down a ramp) // vs. simply forward (off the ramp) Quaternion lTilt = QuaternionExt.FromToRotation(Vector3.up, mActorController._Transform.up); // Move based on WASD we add the tilt lMovement = lTilt * lInput * MovementSpeed * Time.deltaTime; mActorController.Move(lMovement); // ----------------------------------------------------------------- // JUMP // ----------------------------------------------------------------- // Only jump if the button is pressed and we're on the ground if (mInputSource.IsJustPressed("Jump")) { if (mActorController.State.IsGrounded) { mActorController.AddImpulse(mActorController._Transform.up * JumpForce); } } }