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 Issah · Jul 11, 2014 at 02:03 PM · addforce

AddForce on a rigidBody without drift effect (centrifugal force)

Hello Unity community !

I want a sphere which moove in direction of camera forward. That work but when the speed is too high, the drift effect is too strong. When i turn my camera to the right, the sphere need a couple of second to move on camera.forward.

The huge problem is to compensate the forces, when you turn, to obtain a more reactive gameplay.

Im trying to compensate that with the if(), when cam.transform.forward.x between 0 and 1 we turn to the right, if i increase the force value maybe i can compensate the centrifugal effect.

 I have also try Force.Impulse mode 
  
 // This script is on my sphere player
 
 void FixedUpdate () 
 {
     Vector3 mouvment = cam.transform.forward;
             
     if(cam.transform.forward.x != 0) // right if positive, else left
     {
        rigidbody.AddForce(new  Vector3(mouvment.x*30,0,1));
     }
             
       rigidbody.AddForce(mouvment * speed * Time.deltaTime);
 }



Thanks !

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 Issah · Jul 15, 2014 at 09:51 AM 0
Share

Hello,

First thank you for your answers !

I have try both and it's pretty good, the rotation works without centrifugal force ! At least there is one problem :

I fly during some second after a turn, i dont assign the good magnitude on y axe maybe i have try to put 0 ins$$anonymous$$d of cam.transform.forward.y*save$$anonymous$$agn but it dont solve the problem.

 public int speed = 60;
 public int maxSpeed = 25;
 public GameObject cam;
 public float save$$anonymous$$agn;
     
 void FixedUpdate () 
 {
     Vector3 mouvment = cam.transform.forward;
     //  I save the magnitude when there is no input (no turn)
     if(Input.GetAxis("Horizontal") == 0)
     {
         save$$anonymous$$agn = rigidbody.velocity.magnitude;
     }
     else // If i turn, velocity = 0 and reafect the old velocity
     {
         rigidbody.velocity = Vector3.zero;
         rigidbody.velocity = new Vector3(
                                 cam.transform.forward.x*save$$anonymous$$agn,
                                 cam.transform.forward.y*save$$anonymous$$agn,
                                 cam.transform.forward.z*save$$anonymous$$agn);
     }
 
     // I add this force to make my sphere going on camera forward everytime.
     rigidbody.AddForce(mouvment * speed);
 
     // http://answers.unity3d.com/questions/265810/limiting-rigidbody-speed.html i have try this to limite the snowball effect
     if(rigidbody.velocity.magnitude > maxSpeed)
     {
         rigidbody.velocity = rigidbody.velocity.normalized * maxSpeed;
     }
 }
 
 

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by robertbu · Jul 11, 2014 at 02:48 PM

My first suggestion is to up the drag of the rigidbody. The higher the drag, the faster the old velocity will decay and the sooner the new velocity will take hold. You may have to up the amount of force you apply (speed in your code above) to compensate for the drag.

If that is not fast enough, then you can directly assign the velocity. Something like:

 rigidbody.velocity = cam.transform.forward * speed;

This will cause an immediate change in velocity. Note that you don't need multiply by deltaTime inside of FixedUpdate. When inside FixedUpdate, Time.deltaTime will actually be Time.fixedDeltaTime which is a constant.

@Pyassin's suggestion is to only modify the rigidbody.velocity when the camera turns. The code could look like:

 float mag = rigidbody.velocity.magnitude;
 rigidbody.velocity = cam.transform.forward * mag;

This causes an immediate turn but preserves the speed going into the turn.

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 Pysassin · Jul 11, 2014 at 02:35 PM

If you want the thing to turn and remain the speed without it still having a force act on the original rotation (like it would irl) save the magnitude that is before turning then set velocity to 0 and then regive it the velocity in the direction you want with the old magnitude.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

collider not working when apply "addForce" high enough 2 Answers

addforce + persp camera movement weirdness 1 Answer

Rolling Ball Code Isn't Working 6 Answers

OnTriggerEnter AddForce 1 Answer

Raycast Hit Question 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