how to effect slow motion when collision with an object
PS: Unity 5.2 C # script
Answer by G4merSylver · Dec 22, 2015 at 07:44 PM
I wont give you the script but I can tell you how it works.
Firstly, using time.timeScale would give you some kind of slowmotion... but I doubt that having a frame or two per second isnt exactly what you want.
So first you have to attach an script that would dampen the movement of everything that you want in slowmotion, if its a transform movement just multiply it by something around 0.1 or if its an rigidbody you can use mathf.clamp to clamp the velocity. The standard image effects should have an grayscale filter in case you would need that.
Other keyword that might be useful, Interpolation.
I made this code
void OnTriggerEnter2D (Collider2D coll) {if (coll.tag == "player") { Time.timeScale = 0.5f; Destroy (this.gameObject); }
the collision and detected but Time.timeScale = 0.5f command; does not work u think I did something wrong in this code?
Answer by Slender2000 · Sep 10, 2017 at 02:21 PM
I'm not jewish
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class SlowMo : MonoBehaviour {
#region Variabels
public float currentSlowMo = 0.0f;
public float slowTimeAllowed = 2.0f;
#endregion
#region Unity Methods
void Start()
{
}
void OnTriggerEnter()
{
if (Time.timeScale == 1.0)
Time.timeScale = 0.3f;
else
{
Time.timeScale = 1.0f;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
}
if (Time.timeScale == 0.3f)
{
currentSlowMo += Time.deltaTime;
}
if (currentSlowMo > slowTimeAllowed)
{
currentSlowMo = 0.0f;
Time.timeScale = 1.0f;
}
}
}
#endregion