- Home /
slow motion effect in game
I want to create a slow motion effect in my game . I have used
time.timescale = (0 < somevalue <1) ;
but this is effecting my entire scene....i want everything in my scene should go slow except my player object ... Hlink textelp me with this !!!
Answer by Doireth · Feb 02, 2013 at 12:21 PM
While I don't know for sure one way you could do it is multiply player's move speed by
var val : float = 1 / Time.timeScale;
That would increase the movement speed by the difference in the time scale. For example, if the time scale was 0.1 (slow motion) then the player's speed would need to be 10 times faster which would compensate for the difference.
Here's an example (it's written in C# but that it's only to serve as an example)
Normal version
public class TestSlowMo : MonoBehaviour {
private Vector3 originalPos;
// Use this for initialization
void Start () {
originalPos = transform.position;
}
// Update is called once per frame
void Update () {
Vector3 newPos = originalPos;
newPos.x += Mathf.PingPong((Time.time * 10), 10);
transform.position = newPos;
}
}
Time-scale compensating version:
public class TestSlowMo : MonoBehaviour {
private Vector3 originalPos;
// Use this for initialization
void Start () {
originalPos = transform.position;
Time.timeScale = 0.01f;
}
private float _val;
// Update is called once per frame
void Update () {
_val = (1 / Time.timeScale);
Vector3 newPos = originalPos;
newPos.x += Mathf.PingPong((Time.time * 10) * _val, 10);
transform.position = newPos;
}
}
This could be time consuming (sorry I couldn't resist the pun) way to implement the desired effect but it seemed to work well on my test.
hey thanks mate.... i tried ..but seems things are just not working....i am getting very jerky motions
$$anonymous$$y answer requires a lot to integrate it into a full project. Any value that gets incremented over time should be adjusted like in my solution. I have my tested answer and it works perfectly.
There is no easy way to achieve what you are trying to do.
i guess what i'm trying to implement is similar to $$anonymous$$ax Payne's bullet time effect ...is it mate ....? how should i go forward on this from now ?
The code I posted could create such an effect but like I said it won't be easy. Experiment with this but be prepared to spend some time to get the desired result. Applying the timescale compensating value like above to each movement value of the player will allow the player to move at normal speed regardless of timescale.
Answer by AyJayKaySoft · Feb 02, 2013 at 12:26 PM
if (Time.timeScale > 0 && onSlowMotion) {
htranslation /= Time.timeScale;
vtranslation /= Time.timeScale;
}
but with this your character will slow down if timeScale > 1 (so, you could add ( && Time.timeScale < 1) to the if statement, if you want do that). This should work, if timeScale influences deltaTime like I think.... could you write if it works?
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
ScrollView: scroll bar on left side instead of right? 1 Answer
Mono Can't Attach to unity ( for debug ) 2 Answers
Issues with Render Texture 1 Answer