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 blackmethod · Jul 07, 2011 at 05:57 AM · rigidbodyspherecontroladdrelativeforceaddrelativetorque

Sphere movement very erratic and uncontrollable.

Okay, I feel like an idiot asking so many questions. But if you have seen my questions before I was asking how to get a sphere to rotate physically, and how to get a camera to follow it. Both of those were done Yay! But i'm currently faced with a problem. When it starts to rotate, and move. It doesn't seem to stop. Go ahead and open the scripts I post and try it to see what I mean. I have no idea why it's doing it. I thought making it relative would work but I guess not. Here is my code

Sphere Movement:

 function FixedUpdate () {
 if (Input.GetButton("W"))
 {
 
 rigidbody.AddRelativeTorque (0, 0, 2);
 
 rigidbody.AddRelativeForce (0, 0, 2);
 }
 
 
 if (Input.GetButton("S"))
 {
 
 rigidbody.AddRelativeTorque (0, 0, -2);
 rigidbody.AddRelativeForce (0, 0, -2);
 }
 
 if (Input.GetButton("A"))
 {
 rigidbody.AddRelativeTorque (-2, 0, 0);
 rigidbody.AddRelativeForce (-2, 0, 0);
 }
 
 
 if (Input.GetButton("D"))
 {
 rigidbody.AddRelativeTorque (2, 0, 0);
 rigidbody.AddRelativeForce (2, 0, 0);
 }
 }


Camera:

 var target: Transform;
 var damp: float = 0.2;
 var distance: float = 50;
 
 function Update(){
 
     damp = Mathf.Clamp(damp, 0.01, 10); // clamps damping factor
     var pCam = transform.position;
     var pTarget = target.position;
     var diff: Vector3 = pTarget - pCam;  // diff = difference between positions
     var dist = diff.magnitude;  // dist = distance between them
     if (Mathf.Abs(diff.y) < 0.7*distance){
         diff.y = 0;  // doesn't modify camera height unless angle > 45
     } 
     if (dist>distance){ // if distance too big...
         diff *= 1-distance/dist; // diff = position error
         // move a FPS independent little step towards the ideal position
         transform.position = pCam + diff * Time.deltaTime/damp;
     }
     transform.LookAt(pTarget);
 }





Please, to really understand what I mean. Make a blank sphere on a map with a camera and apply these scripts.

Comment
Add comment · Show 5
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 Dreamblur · Jul 07, 2011 at 06:04 AM 0
Share

Does the sphere's rigidbody have a reasonable angular drag?

avatar image blackmethod · Jul 07, 2011 at 06:25 AM 0
Share

That's what it seems like.

avatar image Dreamblur · Jul 07, 2011 at 06:43 AM 0
Share

Torque is an "angular force" that causes both displacement and rotation. You need an angular drag to have the angular velocity stop over time, and a linear drag to have the linear velocity stop over time. Your script works as intended on my comp when the drag and angular drag are set up to a nice value.

avatar image blackmethod · Jul 07, 2011 at 03:15 PM 0
Share

That must be it. I forgot to edit values

avatar image blackmethod · Jul 07, 2011 at 03:19 PM 0
Share

Do you $$anonymous$$d commenting in the values you used?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Waz · Jul 07, 2011 at 06:56 AM

Your code is torquing the object around the axis of motion. That seems wrong: to roll forward (0,0,1), you rotate around the X axis (1,0,0). Run your code with the AddRelativeTorque functions commented-out and then with the AddRelativeForce functions commented out, and see that both are what you intended.

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 blackmethod · Jul 07, 2011 at 04:15 PM 0
Share

I just tried both of the things you two suggested. I tried editing the script so now it's:

function FixedUpdate () { if (Input.GetButton("W")) {

rigidbody.AddRelativeTorque (2, 0, 0);

//rigidbody.AddRelativeForce (2, 0, 0); }

if (Input.GetButton("S")) {

rigidbody.AddRelativeTorque (-2, 0, 0); //rigidbody.AddRelativeForce (-2, 0, 0); }

if (Input.GetButton("A")) { rigidbody.AddRelativeTorque (0, 0, -2); //rigidbody.AddRelativeForce (0, 0, -2); }

if (Input.GetButton("D")) { rigidbody.AddRelativeTorque (0, 0, 2); //rigidbody.AddRelativeForce (0, 0, 2); } }

But it still gets into an uncontrollable spin.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Character Controller - Collision Detection 1 Answer

A sphere moved by relativeforce is acting wierd? 2 Answers

Drag rigidbody.js help 0 Answers

How to make a rigidbody move with wheels? 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