how do i slow down time without slowing down the player
as when i am trying to mimic this:
https://youtu.be/DhCLTO3CzjQ Spider Man 3 Reflex Time comparison against Enemies (added annotations in the form of sub titles)
and
https://youtu.be/1WSV3YCWUtI Spider Man 3 Reflex Time comparison against Train (added annotations in the form of sub titles)
Quantum Break also features this type of Super Speed but it is not availabletried to the player until the player nears the end of the game, tho it is used by enemies early in the game i thinkimplement my own version
and increasing the rate at which physics occur tenfold then slowing that down to emulate Reflex Time would not work would it?
using System; using UnityEngine; using UnityStandardAssets.CrossPlatformInput; namespace UnityStandardAssets.Characters.FirstPerson { [RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(CapsuleCollider))] public class JumpingPhysics : MonoBehaviour { [Serializable] public class AdvancedSettings { public float groundCheckDistance = 0.01f; // distance for checking if the controller is grounded ( 0.01f seems to work best for this ) public float stickToGroundHelperDistance = 0.5f; // stops the character public float slowDownRate = 20f; // rate at which the controller comes to a stop when there is no input public bool airControl; // can the user control the direction that is being moved in the air [Tooltip("set it to 0.1 or more if you get stuck in wall")] public float shellOffset; //reduce the radius by that ratio to avoid getting stuck in wall (a value of 0.1f is nice) } private float m_YRotation; private Rigidbody m_RigidBody; public bool m_PreviouslyGrounded, m_IsGrounded; public Vector3 m_GroundContactNormal; private CapsuleCollider m_Capsule; public AdvancedSettings advancedSettings = new AdvancedSettings(); public float verticalVelocity = 0f; public float gravity = 9.80665f; public float jumpForce = 20.0f; public float MovementSpeed; public float MovementSpeedDefault = 10f; public float forces = 10.0f; public float drag = 10.0f; public CharacterController controller; public float slowdownFactor = 0.005f; public float Matrix_Time = 0; public float Time_Original = 0; public bool Matrix = false; public bool Matrix_Instant_Time = true; public int Matrix_State = 0; public void DoSlowmotion() { Matrix_State = 2; Matrix_Time = slowdownFactor; Time.timeScale = Matrix_Time; } public void DoSpeedUp() { Matrix_State = 3; Matrix_Time += (1f / 1f) * Time.unscaledDeltaTime; Matrix_Time = Mathf.Clamp(Matrix_Time, 0f, 1f); Time.timeScale = Matrix_Time; if (Matrix_Time >= Time_Original) Matrix_State = 0; } public void DoSlowDown() { Matrix_Time -= (1f / 1f) * Time.unscaledDeltaTime; Matrix_Time = Mathf.Clamp(Matrix_Time, 0f, 1f); Time.timeScale = Matrix_Time; if (Matrix_Time < slowdownFactor) Matrix_State = 1; } public void Start() { if (Matrix_Time == 0) Matrix_Time = Time.timeScale; if (Time_Original == 0) Time_Original = Time.timeScale; MovementSpeed = MovementSpeedDefault; m_RigidBody = GetComponent<Rigidbody>(); m_Capsule = GetComponent<CapsuleCollider>(); controller = GetComponent<CharacterController>(); } private Vector3 moveDirection = Vector3.zero; private void Update() { Update1(); } private void Update1() { GroundCheck(); InteractRaycast(); if (controller.isGrounded) { moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= MovementSpeed; if (Input.GetButton("Jump")) moveDirection.y = jumpForce / Matrix_Time; MovementSpeed = MovementSpeedDefault / Matrix_Time; } else { moveDirection.y -= (gravity * Time.fixedUnscaledDeltaTime) / Matrix_Time; } verticalVelocity = moveDirection.y; controller.Move(moveDirection * Time.fixedDeltaTime); if (Input.GetButtonDown("Matrix")) Matrix = !Matrix; if (Matrix) { if (Matrix_Instant_Time) { if (Matrix_State == 0) DoSlowmotion(); } else { if (Matrix_State == 0 || Matrix_State == 3) DoSlowDown(); if (Matrix_State == 1) DoSlowmotion(); } } else { if (Matrix_Instant_Time) { Matrix_Time = Time_Original; Time.timeScale = Matrix_Time; Matrix_State = 0; } else DoSpeedUp(); } Time.fixedDeltaTime = Time.timeScale * .02f; } private Vector2 GetInput() { Vector2 input = new Vector2 { x = CrossPlatformInputManager.GetAxis("Horizontal"), y = CrossPlatformInputManager.GetAxis("Vertical") }; return input; } /// sphere cast down just beyond the bottom of the capsule to see if the capsule is colliding round the bottom private void GroundCheck() { RaycastHit hitInfo; if (Physics.SphereCast(transform.position, m_Capsule.radius * (1.0f - advancedSettings.shellOffset), Vector3.down, out hitInfo, ((m_Capsule.height / 2f) - m_Capsule.radius) + advancedSettings.groundCheckDistance, Physics.AllLayers, QueryTriggerInteraction.Ignore)) { m_IsGrounded = true; m_GroundContactNormal = hitInfo.normal; } else { m_IsGrounded = false; m_GroundContactNormal = Vector3.up; } } void InteractRaycast() { Vector3 playerPosition = transform.position; Vector3 forwardDirection = transform.forward; Ray InteractionRay = new Ray(playerPosition, forwardDirection); RaycastHit InteractionRayHit; float InteractionRayLength = 5.0f; Vector3 InteractionRayEndpoint = forwardDirection * InteractionRayLength; Debug.DrawLine(playerPosition, InteractionRayEndpoint); bool hitfound = Physics.Raycast(InteractionRay, out InteractionRayHit, InteractionRayLength); if (hitfound) { GameObject hitGameObject = InteractionRayHit.transform.gameObject; string hitFeedBack = hitGameObject.name; printfTools.Tools.fprintf(Debug.Log, "FPRINTF raycast hit object with name %s", hitFeedBack); } } } } as i tried to implement my own version but i encounteredencounter the following bugs
when slowing down time beyond 0.005, eg 0.004, the movement code that balances thisthe player speed with the time scale becomes unreliable as the player will move faster than they are supposed to, which should not happen
i tried using Time.FixedDeltaTime and Time.fixedTime but
although the player moves and transitions from normal to slow mo and vice versa exactly how i want it to (basically not noticeable, as if nothing has happened when actually everything is slowed down)
if i put an explosion next to a cube while slowed down the cube physics appear to be lagging a lot, like 0.5 fps which is bad, i need the physics to be real-time but still slowed down with the player
a friend suggested i use a tween effect but i have no experience with those and i cant find any youtube videos about them for use with slow motion
so i am starting from scratch starting with a simple jump then progress through implementing the movement
this is my new script
using System; using System.Collections; using System.Collections.Generic; using Unity; using UnityEngine; using UnityStandardAssets.CrossPlatformInput; public class newjump : MonoBehaviour { Rigidbody R; public float force = 375f; public bool grounded = false; public float ColliderEdge; CharacterController C; // Use this for initialization void Start () { ColliderEdge = GetColliderEdge(); R = GetComponent<Rigidbody>(); C = GetComponent<CharacterController>(); } // Update is called once per frame void Update () { grounded = IsGrounded(); if (grounded) if (Input.GetButton("Jump")) R.AddForce(Vector3.up * force, ForceMode.Impulse); printfTools.Tools.fprintf(Debug.Log, "Physics.Raycast(transform.position, hitInfo, ColliderEdge) = %s", grounded?"true":"false"); } float GetColliderEdge() { if (GetComponent<Collider>().GetType() == typeof(SphereCollider)) { return GetComponent<SphereCollider>().radius; } return 0f; } bool IsGrounded() { RaycastHit hitInfo; return Physics.Raycast(transform.position, -Vector3.up, out hitInfo, ColliderEdge); } } how would i get the jump to... not slow down when the Time.TimeScale changes but in a way that does not introduce any of the bugs previously mentioned