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 boddole · Dec 26, 2013 at 02:55 AM · c#programming

Question on Euler angles and Time.deltaTime

I've been working on a Unity Project "Space Shooter" (http://unity3d.com/earn/tutorials/projects/space-shooter/moving-the-player) and I slightly modified one of the scripts that deals with player movement (and in my case how the player's ship banks according to player speed) and I have included the relevant code at the end of the post.

I've added time.deltaTime as a multiplier into the line: rigidbody.velocity = playerMovement speedModifier Time.deltaTime; Which is then fed into: rigidbody.rotation = Quaternion.Euler (0.0f,0.0f,rigidbody.velocity.x * -tilt)

Now, without time.deltaTime, the Euler math works out exactly as expected (say player movement was 1, speedModifier was 2, and tilt was 5: you would get a max rotation of (1*2) * 5 = 10 degrees.

The problem is that when time.deltaTime is active, I don't understand how the max player rotation is derived (and in this case when applied to small numbers, the player ship barley even moves or rotates at all). Using values that equaled what would normally be 500 degrees with time.deltaTime, I end up with a 10 degree max rotation....how?

Now, of course you could figure that 500 * the value of time.deltaTime must = 10, but I thought that time.deltaTime varies from frame to frame (and I doubt every frame even in a simple game renders at the exact same speed), so there should be some variance each time I turn (say 10, 10.2, 10.05, etc). But every time I turn, I get 10, and I don't know why. Any ideas?

 public float speedModifier = 100.0f;
 public float tilt = 5.0f;
 
     void FixedUpdate () {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
 
         Vector3 playerMovement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
         rigidbody.velocity = playerMovement * speedModifier * Time.deltaTime;
 
         rigidbody.rotation = Quaternion.Euler (0.0f,0.0f,rigidbody.velocity.x * -tilt);
     }
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 robertbu · Dec 26, 2013 at 03:34 AM

In FixedUpdate(), Time.deltaTime is changed to be equal to Time.fixedDeltaTime. From the reference on Time.deltaTime:

When called from inside MonoBehaviour's FixedUpdate, returns the fixed framerate delta time.

The default value for fixedTimeStep is 0.02. You can change this value in:

 Edit > Project Settings > Time

So if you want to play with you code, either change 'FixedUpdate' to 'Update', or change the fixedTimeStep.

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 boddole · Dec 27, 2013 at 01:57 AM 0
Share

Thank you for your answer.

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

18 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

Related Questions

Multiple Cars not working 1 Answer

Question on C# Interface Method Parameters 3 Answers

A node in a childnode? 1 Answer

What should i learn for unity C# or UnityScript? 4 Answers

C# GameObject Lists 2 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