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 MK7 · Apr 12, 2011 at 11:35 PM · javascriptbuildrun

Rotation accuracy in build

I'm having an issue keeping my object rotating in 90 degree increments when I build and run my game. However it seems to work fine in the editor and I know this should be working

Any help would be greatly appreciated. Here's the code i'm currently using

var Player : Transform; var rotateAmount = 90; var rotateTime = float;

function Update () { if ( Input.GetKeyDown("z")) // point, axis, amount, time RotateObject(Player.position,Vector3.forward, 90,1.0);

 if  (Input.GetKeyDown("x"))

     RotateObject(Player.position,Vector3.back, 90,1.0);

 if  (Input.GetKeyDown("c"))

     RotateObject(Player.position,Vector3.left, 90,1.0);

 if  (Input.GetKeyDown("v"))

     RotateObject(Player.position,Vector3.right, 90,1.0);

}

function RotateObject(point : Vector3, axis : Vector3, rotateAmount : float, rotateTime : float) { var step : float = 0.0; //non-smoothed var rate : float = 1.0/rotateTime; //amount to increase non-smooth step by var smoothStep : float = 0.0; //smooth step this time var lastStep : float = 0.0; //smooth step last time while(step < 1.0) { // until we're done step += Time.deltaTime rate; //increase the step smoothStep = Mathf.SmoothStep(0.0, 1.0, step); //get the smooth step transform.RotateAround(point, axis, rotateAmount (smoothStep - lastStep)); lastStep = smoothStep; //store the smooth step yield; } //finish any left-over if(step > 1.0) transform.RotateAround(point, axis, rotateAmount * (1.0 - lastStep)); }

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 Eric5h5 · Apr 13, 2011 at 12:17 AM

"var rotateTime = float" is incorrect syntax and won't work. Anyway, it looks like the main issue is that you have nothing to prevent rotating while a rotation is already in progress. Either rewrite the Update function as a coroutine and yield on the RotateObject routine, so input isn't checked while it's running and therefore unwanted rotations are impossible, or have some kind of variable that's set true when rotating and false when not, and don't allow the routine to run if the variable is true.

Comment
Add comment · Show 6 · 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 MK7 · Apr 13, 2011 at 06:20 AM 0
Share

Ok I'll give it a shot thank you!

avatar image MK7 · Apr 13, 2011 at 07:46 AM 0
Share

It doesn't seem to be working. The problem is my rotation is co$$anonymous$$g up to short. I want it to be a 90 degree rotation but it seems to only do about half of that. Any ideas?

avatar image Eric5h5 · Apr 13, 2011 at 08:00 AM 0
Share

The RotateObject function seems to be based on time. I guess you'd want to rewrite that so it's based on degrees rotated ins$$anonymous$$d.

avatar image MK7 · Apr 16, 2011 at 05:22 AM 0
Share

I hate to be a bother but you wouldn't happen to know how to do that would you? or at least have an idea on where I could look perhaps? I've been racking my brain trying to get it to work correctly and to be honest I'm a noob at javascript

avatar image Eric5h5 · Apr 16, 2011 at 07:23 AM 0
Share

@$$anonymous$$$$anonymous$$7: See the Rotation function here: http://www.unifycommunity.com/wiki/index.php?title=$$anonymous$$oveObject

Show more comments

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

No one has followed this question yet.

Related Questions

mecanim run animation script trouble 0 Answers

Running batch script or .exe after "build&run" 1 Answer

Distribute terrain in zones 3 Answers

OnTriggerEnter2D Rapid Fire 0 Answers

9 errors in Javascript 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