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 naqvir · Feb 22, 2012 at 03:28 PM · rotationrigidbodycontrollerspacerotating

Controlling an asteroid using a rigidbody.

Hey guys i was wondering if you could give me some advice on how to approach this problem i am having. I have some code written , but its not working the way i want it to. I want the player to control an asteroid that they can move around in space. This is the code i have so far which doesnt work.


public var cameraa:Transform;

var smooth:float =5.0f;

var rotationSpeed:float = 10f;

var accnSpeed:float = 10f;

function Update () {

 var currentRotationX:float = gameObject.transform.rotation.x;
 
 if(Input.GetKey(KeyCode.W)) {
     if(currentRotationX < 60 || currentRotationX > 360-60 )
         gameObject.rigidbody.AddTorque(-rotationSpeed*Time.deltaTime,0,0);
 }
 if(Input.GetKey(KeyCode.A)) {
     gameObject.rigidbody.AddTorque(0,-rotationSpeed*Time.deltaTime,0);
 }
 if(Input.GetKey(KeyCode.D)) {
     gameObject.rigidbody.AddTorque(0,rotationSpeed*Time.deltaTime,0);
 }
 if(Input.GetKey(KeyCode.S)) {
     if(currentRotationX < 60 || currentRotationX > 360-60)
         gameObject.rigidbody.AddTorque(rotationSpeed*Time.deltaTime,0,0);            
 }
 if(Input.GetKey(KeyCode.X)) {
     gameObject.rigidbody.AddRelativeForce(Vector3.forward*accnSpeed*Time.deltaTime);
     
 }
 

}

At the moment the code makes me rotate too far as i hold down WASD, i want to limit the rotation of the asteroid so it doesnt rotate out of control, i also want it to accelerate in the forward direction of my controller direction. Please help help help , been trying to sort this out for weeks, am not getting far at all... :( im only starting out using unity and cant find any 3rd person controllers for space games that are free. Thanks guys, would appreciate the helo tons

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 adrenak · Feb 22, 2012 at 06:27 PM

If you want to prevent the asteroid from spinning out of control then you have to limit the angular velocity to a maximum value use this : rigidbody.maxAngularVelocity = thevalueyouwant;

I an not sure if you should have it in the update function to call it every frame or not. Try making a function Start ( start with a capital s ) and have it in there, if it doesn't work there then try it adding to the update function.

I Hope this helped!

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

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

6 People are following this question.

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

Related Questions

Issue with Rotation behaviour of PID Controller when rotating to look at mouse position 0 Answers

How to Convert dir = (a.transform.position - b.transform.position).normalized; to Degrees ? 1 Answer

Resetting transform's original position and rotation after using transform.rotateAround 1 Answer

click to move workig script!! but pls help with rotation!! :( 1 Answer

Sphere rotation in moving direction 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