Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 $$anonymous$$ · May 08, 2018 at 08:08 PM · rotationscripting problemfpstime.deltatime

if the fps is high the camera rotate much faster

if the fps is high the camera rotate much faster. how can I make sure that it does not matter what fps you have and it does not rotate faster or slower

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 
 public class CameraControl : MonoBehaviour
 {
     public Slider zoomSlider;
 
     private const float Y_ANGLE_MIN = 1.0f;
     private const float Y_ANGLE_MAX = 60.0f;
 
     public Transform lookAt;
     public Transform camTransform;
     public float distance = 5f;
 
     private float currentX = 0.0f;
     private float currentY = 45.0f;
 
     public Joystick joystick;
 
     public bool joystickEnabled = true;
 
     private void Start()
     {
         camTransform = transform;
     }
     private void Update()
     {
 
         if (joystickEnabled == false)
         {
             currentX += Input.GetAxis("Horizontal");
             currentY -= Input.GetAxis("Vertical");
         }
         else
         if (joystickEnabled == true)
         {
             currentX += joystick.Horizontal;
             currentY -= joystick.Vertical;
         }
 
         currentY = Mathf.Clamp(currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
     }
 
     private void LateUpdate()
     {
         Vector3 dir = new Vector3(0, 0, -distance);
         Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
         camTransform.position = lookAt.position + rotation * dir;
         camTransform.LookAt(lookAt.position);
     }
 
     public void Zoom()
     {
         distance = zoomSlider.value;
     }
 }


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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by TreyH · May 08, 2018 at 08:14 PM

Well, you aren't normalizing anything by time. Update and LateUpdate will run as fast as the client machine can process frames. As a result, you'll want to make sure there's a time-dependent coefficient on any sort of movement happening there:

 if (joystickEnabled == false)
 {
       currentX += Input.GetAxis("Horizontal") * Time.deltaTime;
       currentY -= Input.GetAxis("Vertical") * Time.deltaTime;
 }
 else
 {
       currentX += joystick.Horizontal * Time.deltaTime;
       currentY -= joystick.Vertical * Time.deltaTime;
 }


When you first implement this, your rotation will be much slower than it was. People typically have an additional coefficient to tune how quickly the now-normalized rotation occurs.

Comment
Add comment · Show 3 · 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 fluxhackspro · May 09, 2018 at 08:29 AM 1
Share

Also don't forget that if you manipulate the timescale or the speed of the game the time.deltatime will be affected too. To avoid this use time.fixedDeltatime

avatar image Eno-Khaon fluxhackspro · May 09, 2018 at 08:48 AM 1
Share

If Time.timeScale has been adjusted and you still wish to rotate at a fixed rate regardless of that timeScale, you can use it as a modifier of that rate.

 if(Time.timeScale > 0) // Divide-by-zero safety
 {
     float rotationRateX = (sensitivityX * Input.GetAxis("Horizontal") * Time.deltaTime) / Time.timeScale;
 }


By extension, when using $$anonymous$$ouse movement for input, you likely wouldn't want to scale the result by time in any manner.

avatar image TreyH fluxhackspro · May 09, 2018 at 11:29 AM 0
Share

Time.fixedDeltaTime is actually for the physics cycle and FixedUpdate. To account for scaled time, you can just use Time.unscaledDeltaTime.

Ty for the re$$anonymous$$ders, scaled time slipped my $$anonymous$$d.

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

198 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems with player movement at higher frame rates (Time.deltaTime not producing consistent results) 1 Answer

orienting player in one direction 1 Answer

Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 Answers

How do I make an object rotate gradually using Rigidbody2D.MoveRotation() 3 Answers

Character controller without Deltatime 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