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 /
This question was closed Jan 16, 2018 at 12:22 PM by PlayCreatively for the following reason:

I'm not getting helpful answers do to people not actaully reading my whole question or not understanding it.

avatar image
0
Question by PlayCreatively · Jan 15, 2018 at 10:48 PM · gravityaddforcespeedaccelerationlimit

Insure that the player can't increase speed when over the speed limit

We're working with a space shuttle in zero-G that can only thrust forward.

How do I go about insuring that the player can't just accelerate infinitly but instead can only thrust up to a certain top speed and also without limiting the possible speed the shuttle could end up in (If perhaps it gets hit by an asteroid or something).

I've tried so many things but for some reason the results don't make sense to me. Like for one instance the shuttle didn't thrust past the top speed but when I slightly turned and kind if drifted in space I accelerated way beyond my top speed, only moving to the left but not actually forward. I can kind of guess why it happened but I can't easily comprehend the problem to think of a solution.

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

3 Replies

  • Sort: 
avatar image
-1

Answer by RedDeCipher · Jan 15, 2018 at 11:01 PM

It should be something like this

 const float MaxSpeed = *Something*;
 const float regularAcceleration = *Acceleration*;
 
 if(velocity >= MaxSpeed){
     velocity = MaxSpeed
     acceleration = 0;
 
 }else
      acceleration = regularAcceleration ;
Comment
Add comment · Show 3 · 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 PlayCreatively · Jan 15, 2018 at 11:37 PM 0
Share

No. I don't want to clamp the velocity. It's also more complicated than this. I've already tried something like this and the results were terrible.

avatar image RedDeCipher PlayCreatively · Jan 15, 2018 at 11:44 PM 0
Share

Oh okay, you can put a time limit something like

 const int countdown = 300(for example);
 
 if(countdown > 0){
     vellocity += aceleration;
     countdown---;
 }else
     //Don't accelerate


So it wont be clamped but ship will stoped accelerating after a while you can even base the time on other variables.

avatar image RedDeCipher PlayCreatively · Jan 15, 2018 at 11:50 PM 0
Share

Oh wait now I get what you are trying to say, You should set a fake velocity that will increase even after acceleration stops like and continue to add that.

  const float $$anonymous$$axSpeed = *Something*;
 float fakeVelocity;
  
  if(velocity >= $$anonymous$$axSpeed){
      velocity = $$anonymous$$axSpeed
       fakeVelocity += acceleration;
  }else{
       velocity += acceleration;
       fakeVelocity = velocity;
 }
 
 

Then use it to calculate force when you collide with something

avatar image
0

Answer by Dray · Jan 16, 2018 at 12:16 AM

If you don't want to clamp the velocity, what you need is some kind of friction, even though that doesn't make much sence in space ,heh. The easiest thing to do would probably be to define a friction value between zero and one (~percentage) and multiply your speed with (1 - friction). For example, 10% friction:

 float friction = 0.1f; // = 10%

 void FixedUpdate() {
     speed *=  (1 - friction);
 }
 

This will make you lose 10% of your current speed in every physics frame. Make sure you put it in FixedUpdate() and play around with the percentage. You will need to increase your acceleration to counteract the friction

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 Ginxx009 · Jan 16, 2018 at 01:11 AM

Well if you want to make sure that your object will not increase over speed limit is that do an if else statement so we can go something like this

 float speed = 10.0f;
 float speedLimit = 15.0f;
 
 if(speed > speedLimit){
 //reduce speed here
 }

It's not the actual code okay. So what i am telling you is the logic behind it. Or there's another way of doing it. You can use Mathf.Clamp. Use it on the rigidbody.velocity values after the force is applied to determine speed caps.

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

Follow this Question

Answers Answers and Comments

78 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to reach a specific max speed with AddForce() ? 1 Answer

How do i make the Impulse i give to my Player not be lowered by acceleration of gravity? 1 Answer

AddForce for spaceship acceleration, but with max speed 2 Answers

How to limit the force from player input without limiting speed 2 Answers

Ball Addforce Acceleration Speed 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