Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by deodatopr · Dec 31, 2012 at 05:13 PM · slowmotion

Slowmotion in some GameObjects

Hello Guys,

I want to create the effect to slow-motion in the scene I can use (Time.timeScale), but this one controls the entire scene.

Questions: I want to control the speed (Like 0.3) of the entire scene, but only the player can move at the normal speed (Like 1.0)... It's possible to control by separated the GameObjects in Unity?

Thanks,

Deo.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Lovrenc · Dec 31, 2012 at 05:50 PM

You can control character in accordance to real time and all other objects with game time. This way, player wont be affected by timeScale.

EDIT: On the top of your class add variable:

 float previousFrameTime = 0;

Then in update you do:

 float currentTime = Time.realtimeSinceStartup;
 float deltaTime = currentTime - reviousFrameTime;
 previousFrameTime = currentTime;

deltaTime is the var you use then.

EDIT: your script fixed

 using UnityEngine;
 using System.Collections;

 public class AI_Forward_Speed : MonoBehaviour
 {    
     
     float previousFrameTime = 0;
     
     void Update ()
     {
         if (Input.GetKeyDown (KeyCode.Mouse0)) {
             Time.timeScale = 0.1f;
             print ("Activated it");
         }
         if (Input.GetKeyDown (KeyCode.Mouse1)) {
             Time.timeScale = 1.0f; 
             print ("Desactivate ir");
         }
 
         float currentTime = Time.realtimeSinceStartup;
         float deltaTime = currentTime - previousFrameTime;
         previousFrameTime = currentTime;
 
         transform.Translate (Vector3.forward * deltaTime * 0.6f, Space.Self);    
     
     }
     
     //End
 }


Comment
Add comment · Show 12 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image deodatopr · Dec 31, 2012 at 05:59 PM 0
Share

But when you use "Time.ScaleTime" apply it to the Entire Scene, how can I use "Time.realtimeSinceStartup" just with the Player or any Object that I need?

Deo :)

avatar image Lovrenc · Dec 31, 2012 at 06:12 PM 0
Share

You make controller script that is usint realtime ins$$anonymous$$d of Time.deltaTime. ScaleTime is NOT CONTROLING realtime.

You can also create a static variable to add to all objects that are to be slow and divide deltaTime with that.

avatar image deodatopr · Dec 31, 2012 at 11:55 PM 0
Share

thanks, but if I use realtime, the character accelerate progressively, be cause this class it's about the time since start the game :(

avatar image Lovrenc · Jan 01, 2013 at 12:10 AM 0
Share

Time.deltaTime is time between frames. You do same here. Have var that holds realTime from previous frame. Now in update you do:

deltaTime = currentTime - previousTime

and use that for movement....

avatar image deodatopr · Jan 01, 2013 at 12:55 AM 0
Share

Looks the same, it's accelerated the time, since pass the seconds, I'm using this:

RealTime = Time.time - Time.realtimeSinceStartup;

am I correct?

Deo.

Show more comments
avatar image
0

Answer by Michel-Tonon · Jan 19, 2017 at 06:00 PM

I'm new in unity. My solution...

 void FixedUpdate()
     {
         if (slowMotion)
         {
             if (!Rigidbody.isKinematic)
                 velocity = Rigidbody.velocity;
 
             Rigidbody.isKinematic = !Rigidbody.isKinematic;
 
             if (!Rigidbody.isKinematic)
                 Rigidbody.AddForce(velocity, ForceMode.Impulse);
         }
     }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Time.timeScale is laggy 2 Answers

Calcule Player's Speed based on Time.timeScale 1 Answer

slow motion effect in game 2 Answers

Addforce function for an Instantiated object is not working after slow motion effect! 0 Answers

Time.timeScale is Having a Strange Effect on Physics 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges