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 Hjalte · Jul 11, 2014 at 04:06 AM · c#first-person-controllerlaggytime.timescaleslowmotion

Time.timeScale is laggy

Okay Im making kinda off like a SuperHot inspired game. The idea is that when you rightclick everything goes into slowmotion except the player. Ive done this by setting the Time.timeScale to 0.2f and then multiplying all charachter movement with 5 so that it has the same speed as if the Time.timeScale was set to 1 and it had its normal speeds. It works but its super laggy. While I still have 2000fps the character is seems to only be moving once every half second or so. Anyone have any explanation to this problem? heres my script: using UnityEngine; using System.Collections; public class AmazingSlowMo : MonoBehaviour { public float slowMotionSpeed = 5.0f; //public bool slowMoOn; //public bool slowMoOff; private MouseLook mouseLook; private MouseLook mouseLook2; private CharacterMotor charMotor; void Awake () { mouseLook = transform.GetComponent<MouseLook>(); mouseLook2 = GameObject.FindGameObjectWithTag(Tags.mainCamera).GetComponent<MouseLook>(); charMotor = transform.GetComponent<CharacterMotor>(); } void Update() { if (Input.GetButtonDown("Fire2")) { if (Time.timeScale == 1.0F){ Time.timeScale = 0.2F; slowMotionSpeed = 5.0f; SlowMotionOn(); } else{ Time.timeScale = 1.0F; Time.fixedDeltaTime = 0.02F * Time.timeScale; slowMotionSpeed = 5.0f; SlowMotionOff(); } } } void SlowMotionOn(){ mouseLook.sensitivityX = mouseLook.sensitivityX * slowMotionSpeed; mouseLook2.sensitivityY = mouseLook2.sensitivityY * slowMotionSpeed; charMotor.movement.maxForwardSpeed = charMotor.movement.maxForwardSpeed * slowMotionSpeed; charMotor.movement.maxSidewaysSpeed = charMotor.movement.maxSidewaysSpeed * slowMotionSpeed; charMotor.movement.maxBackwardsSpeed = charMotor.movement.maxBackwardsSpeed * slowMotionSpeed; charMotor.movement.maxGroundAcceleration = charMotor.movement.maxGroundAcceleration * slowMotionSpeed; charMotor.movement.maxAirAcceleration = charMotor.movement.maxAirAcceleration * slowMotionSpeed; charMotor.movement.gravity = charMotor.movement.gravity * slowMotionSpeed; charMotor.movement.maxFallSpeed = charMotor.movement.maxFallSpeed * slowMotionSpeed; } void SlowMotionOff(){ mouseLook.sensitivityX = mouseLook.sensitivityX / slowMotionSpeed; mouseLook2.sensitivityY = mouseLook2.sensitivityY / slowMotionSpeed; charMotor.movement.maxForwardSpeed = charMotor.movement.maxForwardSpeed / slowMotionSpeed; charMotor.movement.maxSidewaysSpeed = charMotor.movement.maxSidewaysSpeed / slowMotionSpeed; charMotor.movement.maxBackwardsSpeed = charMotor.movement.maxBackwardsSpeed / slowMotionSpeed; charMotor.movement.maxGroundAcceleration = charMotor.movement.maxGroundAcceleration / slowMotionSpeed; charMotor.movement.maxAirAcceleration = charMotor.movement.maxAirAcceleration / slowMotionSpeed; charMotor.movement.gravity = charMotor.movement.gravity / slowMotionSpeed; charMotor.movement.maxFallSpeed = charMotor.movement.maxFallSpeed / slowMotionSpeed; } }

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
Best Answer

Answer by Kiwasi · Jul 11, 2014 at 04:12 AM

Your CharacterMotor class is probably doing movement in FixedUpdate(). To change the speed of FixedUpdate you need to change Time.fixedDeltaTime every time you change Time.timeScale. In other words copy line 25 to line 19.

Comment
Add comment · Show 1 · 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 Hjalte · Jul 11, 2014 at 12:05 PM 0
Share

That works great thank you. One more question though. I still seem to be sliding around when in slowmotion. Even if i disable sliding or put all values to 0. Would you happen to know why that is?

avatar image
1

Answer by Pysassin · Jul 11, 2014 at 04:12 AM

Have you tried using a unscaled time for using character movement in your motor? I mean the actual script that translates or adds force? I'm referring to http://docs.unity3d.com/ScriptReference/Time-unscaledDeltaTime.html. Using that means even if you change the Time.timeScale you don't need to alter anything on your character because it will run just like it did before.

Comment
Add comment · Show 1 · 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 Kiwasi · Jul 11, 2014 at 04:16 AM 0
Share

That's a neat trick.

Just be warned it could cause problems if your game ever requires you to adjust the player speed.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Make code less laggy? and one object in trigger rather than all? 2 Answers

Flip over an object (smooth transition) 3 Answers

Help with reward player after 24 hours has passed (save time on exit, read on launch) 3 Answers


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