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 Disaster · Nov 04, 2010 at 02:05 PM · physicsrigidbody

Spaceship physics - adding resistance

Hi,

I don't know enough about PhysX (or actual physics!) so was wondering if someone could help me out.

I'm trying to create some simple spaceship controls on a rigidBody. I am doing this by using AddForce to add a direction vector and move the ship accordingly. The problem is (rather obviously), once I have added the force, it stays in effect endlessly. I obviously need to add some kind of resistance to the ship so that after I move in a direction, it slowly comes to a stop (which is specified by the resistance variable or whatever.)

Firstly, is using AddForce the wrong thing to do? Secondly, can anyone suggest a method in which I could apply resistance to my equation:

var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

if (directionVector != Vector3.zero) { var directionLength = directionVector.magnitude; directionVector = directionVector / directionLength;

 directionLength = Mathf.Min(1, directionLength);

 directionLength = directionLength * directionLength;

 directionVector = directionVector * directionLength;

}

gameObject.rigidbody.AddForce(directionVector);

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

2 Replies

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

Answer by Proclyon · Nov 04, 2010 at 02:23 PM

Every force has an equally strong reaction. Action is reaction.

If you hit something from left to right, you can hit it from right to left aswell using a timer or anything else depending on your desired result.

If you are in space and hit something, you will not see the real reactions in games. So just cheat and make a % of the force added to be added on opposite over a time period.

Velocity -= (Decelleration + Time.deltaTime);

Comment
Add comment · Show 5 · 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 Disaster · Nov 04, 2010 at 02:47 PM 0
Share

Where abouts would velocity come into play in the code sample I posted? I'm a little bit confused how I'd work that in.

avatar image runonthespot · Nov 04, 2010 at 02:50 PM 0
Share

Assu$$anonymous$$g your code above runs only when for example you're pressing a key, then when you're not pressing a key, drag will slowly reduce the velocity until you stop. I use similar code for my spaceship game, using Force$$anonymous$$ode.Acceleration as the type of force added.

avatar image Proclyon · Nov 04, 2010 at 02:54 PM 0
Share

I was giving you an explanation in physics. You are going to have an object and it is going to have a speed ($$anonymous$$a.) Velocity, which is distance over time.

You can measure it or just extract it from the rigidbody.

To do that just get the RB out of object with if (GetComponent() != null) { RigidBody myRB = GetComponent(); }

private float velocity = myRB.velocity;

avatar image runonthespot · Nov 04, 2010 at 02:55 PM 0
Share

or in your sample above, Debug.Log(gameObject.rigidbody.velocity); (or something like that)

avatar image Disaster · Nov 04, 2010 at 03:14 PM 0
Share

Thanks, I think I have enough to go on for now :)

avatar image
4

Answer by Atnas1010 · Nov 04, 2010 at 02:12 PM

Try setting the drag to something like 1, and just play around with it.

Angular drag is for slowing rotation speeds.

In actual space, you wouldn't slow down, because there is nothing to slow you down. But that might make a pretty crazy game.

And using AddForce is the right thing to do (if you get the desired result)

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

No one has followed this question yet.

Related Questions

Performance Question on Kinematic Rigidbodies 1 Answer

Dragging ONE rigidbody 1 Answer

Same reaction with different number of objects colliding 2 Answers

Modifying height directly on a Rigidbody Object without gravity 1 Answer

Rigidbody Sliding UP Incline 0 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