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 alone1992 · Mar 07, 2013 at 05:06 PM · forcerigidbody physicsflightaddrelativeforce

problem with changing direction of relative force

Hello every one I have problem with my code and when I change the direction of my object the relative force don't change properly and my object get out of control. I need to know how can I change my force direction smoothly and quickly? I write this code in Update and next in Fixed update and test it with AddForce and AddRelativeForce but in none of them I can't find my answer.

     var UpForce : float;
     var MaxSpeed : float = 100;
     var MinSpeed : float;
     var Speed : float = 1;
     var Acceleration : float = 100;
 function Update () {
     UpForce = rigidbody.velocity.z/10;
     UpForce = Mathf.Clamp(UpForce,0,7);
     rigidbody.AddForce(0,UpForce,0);
     // speed control
     Speed = Mathf.Clamp(Speed,MinSpeed,MaxSpeed); 
     if(Speed <= MinSpeed){
     Speed = MinSpeed;
     }
     if(Speed >= MaxSpeed){
     Speed = MaxSpeed;
     }
     if(Input.GetKey(KeyCode.B)){
     Speed = Speed + 1;
     }
     if(Input.GetKey(KeyCode.N)){
     Speed = Speed - 1;
     }
     if(Input.GetKey(KeyCode.A)){
     transform.Rotate(0,0,Acceleration*Time.deltaTime);
     }
     if(Input.GetKey(KeyCode.D)){
     transform.Rotate(0,0,-Acceleration*Time.deltaTime);
     }
     if(Input.GetKey(KeyCode.S)){
     transform.Rotate(-Acceleration*Time.deltaTime,0,0);
     }
     if(Input.GetKey(KeyCode.W)){
     transform.Rotate(Acceleration*Time.deltaTime,0,0);
     }
     Debug.Log("force:" &&  rigidbody.AddRelativeForce.z);
 }
 function FixedUpdate(){
 rigidbody.AddRelativeForce(0,0,Speed);
 }
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 alone1992 · Mar 08, 2013 at 07:25 AM 0
Share

any one!! any comment!

1 Reply

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

Answer by alone1992 · Mar 08, 2013 at 05:44 PM

I think the Unity3d have bug in this case or it's very very hard to control this force and I use the rigidbody.velocity for my script and every thing solved. but the realism of my game get very low.

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

10 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

Related Questions

Is there a way to add a variable in rigidbody? (like .position) 1 Answer

How to make RigidBody's movement using fixed movement/velocity and other forces all together? 3 Answers

How to apply a radial force 2 Answers

Rigidbody physics; forces doesnt move gameobject in a desired way 1 Answer

How to implement Mob movement / death ? 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