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 formidable · Sep 07, 2011 at 01:30 AM · rotatevelocitytorqueoverrideconstantforce

I WILL GIVE YOU 3 DOLLARS to answer this constantforce question

I'll paypal you 3 dollars(I'm poor as fuck) if you can fix my script so that it works the way I want it to work, it's driving me crazy! For some reason the later if statement cancels out the first one. Here's my code:

private var rotateSpeed : float = 0.0; private var flipSpeed : float = 0.0; var speedness : float = 20.0;

function StartSpinning () {
rigidbody.constantForce.relativeTorque = Vector3 (0, rotateSpeed * Time.deltaTime, 0); }

function StartFlipping () {
rigidbody.constantForce.relativeTorque = Vector3 (0, 0, flipSpeed * Time.deltaTime); }

function FixedUpdate () { if (Input.GetKey("left")) { rotateSpeed = speedness; StartSpinning();
}
if (!Input.GetKey("left")) { rotateSpeed = 0; StartSpinning(); }
if (Input.GetKey("up")) { flipSpeed = -speedness; StartFlipping();
}
if (!Input.GetKey("up")) { flipSpeed = 0; StartFlipping(); }

 }

Comment
Add comment · Show 1
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 testure · Sep 07, 2011 at 02:19 AM 7
Share

How about some free advice ins$$anonymous$$d:

  • format your code, if it's not easily readable people (such as myself) aren't even going to waste our time trying to decipher it.

  • Don't repost your question several times per day. People use the "unanswered" filter (among others) to see who is still waiting for an answer, or has not received a satisfactory answer. There is no need to repost questions over and over again (this is your third time posting the same question in less than four hours. imagine if everybody did that.. this site would be a cesspool.

  • Leave the CAPS and hyperbole out of your question topic. We don't care how desperate you are, if someone can help you solve your problem they will help. Bad manners will just cause people to avoid your question entirely.

4 Replies

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

Answer by aldonaletto · Sep 07, 2011 at 03:05 AM

StartSpinning and StartFlipping are zeroing all axes but the one they set, so the later always cancels the former. You should alter only the axis used in each function. Additionally, you should not multiply the speeds by Time.deltaTime (it may even work, since in FixedUpdate it's usually fixed to 0.020):

function StartSpinning () { rigidbody.constantForce.relativeTorque.y = rotateSpeed * 0.02; }

 function StartFlipping ()
 {    
     rigidbody.constantForce.relativeTorque.z = flipSpeed * 0.02;
 }

If this answer solve your problem, please click the "check" button below the voting thumbs to mark it as accepted - and save your 3 bucks by now: if you get rich someday I'll send a Paypal money request to you with the interest rates added.

Comment
Add comment · Show 2 · 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 formidable · Sep 07, 2011 at 10:58 PM 0
Share

Holy shit that works, thank you so much! Sorry about the noobiness, I'm used to immature forums where you need to shout to be heard. If ever you change your $$anonymous$$d, let me know and I'll hook you up with that 3 dollars.

avatar image CHPedersen · Sep 08, 2011 at 06:34 AM 0
Share

Added an upvote because in addition to being correct, I like the idea of interest rates on the 3 bucks. ;)

avatar image
0

Answer by ThomasQ · Sep 07, 2011 at 01:35 AM

Try using Input.GetAxis("Horizontal"), this does what you want without having to go through each individual key.. Here's the scriptreference.

Comment
Add comment · Show 2 · 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 formidable · Sep 07, 2011 at 01:45 AM 0
Share

That didn't work. Thanks for giving it a shot though. Anybody else?

avatar image formidable · Sep 07, 2011 at 02:03 AM 0
Share

I tried this and it didn't work at all.

var flipSpeed : float = 10.0; var rotateSpeed : float = 10.0;

function FixedUpdate () { var translation : float = Input.GetAxis ("Vertical") flipSpeed; var rotation : float = Input.GetAxis ("Horizontal") rotateSpeed;

     if (Input.GetAxis("Vertical"))
     {
     rigidbody.constantForce.relativeTorque = Vector3 (0, 0, flipSpeed * Time.deltaTime);
     }
     if (Input.GetAxis("Horizontal"))
     {
     rigidbody.constantForce.relativeTorque = Vector3 (0, rotateSpeed * Time.deltaTime, 0);
     }
 }
avatar image
0

Answer by Spartan301 · Sep 07, 2011 at 03:03 AM

Try replacing your second and fourth if statements, the ones with if(!Input...), with else statements. Also, is the code running or are you getting compile errors.

Try replacing your second and fourth if statements, the ones with if(!Input...), with else statements. Also, is the code running or are you getting compile errors.

Or if you want to use Input.GetAxis, try this:

 private var rotateSpeed : float = 10.0; 
 private var flipSpeed : float = 10.0; 
 
 function FixedUpdate () { 
     var torqueY = Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime;
     var torqueZ = Input.GetAxis("Vertical") * flipSpeed * Time.deltaTime;
     rigidbody.constantForce.relativeTorque = Vector3 (0, torqueY, torqueZ); 
     
 }

 I would recommend the GetAxis approach because it has much cleaner code.
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
avatar image
0

Answer by Scribe · Sep 07, 2011 at 05:17 PM

 var rotateSpeed : float = 0.0;
 var flipSpeed    : float = 0.0;
 var speedness : float = 20.0;
     
 function Update (){
     if (Input.GetKey("left")){
         rotateSpeed = speedness;    
     }    
     else{
         rotateSpeed = 0;
     }
         
     if (Input.GetKey("up")){
         flipSpeed = -speedness;    
     }    
     else{
         flipSpeed = 0;
     }
     
     rigidbody.constantForce.relativeTorque = Vector3 (0, rotateSpeed, flipSpeed);    
 }

try this, it worked for me for what I was guessing you were trying to make it do however as you didn't say exactly the effect you were trying to achieve I might have been doing the wrong thing

Scribe

P.S I don't want your money :)

Comment
Add comment · Show 2 · 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 Scribe · Sep 07, 2011 at 05:18 PM 0
Share

oh and you can change the vars back to private just it is easier to see where the problems are if I could see there values in the inspector

avatar image formidable · Sep 07, 2011 at 10:51 PM 0
Share

That makes both the constant force's work but it stops their momentum once the other keys are pressed. aldonaletto's answer is exactly what I was looking for. Thanks for trying though!

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

7 People are following this question.

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

Related Questions

jump and backflip(rotate) like in altos adventure 0 Answers

Im using add force to make a 'ship' go forward, if i release the key is there any way to slow it gradually? 1 Answer

how to rotate velocity/ tying movement to camera 0 Answers

Rotate to look at with physics 2 Answers

add force to rotation 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