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 djfluffwug · Oct 14, 2011 at 05:45 AM · rigidbodyspeedaxislimit

Limit Speed One Axis

Hello, I was wondering how to limit speed on one axis for an object. I have a script that limits speed for my game object but when the object falls it is also limited.

How can I limit the speed of just one axis? Thanks

Comment
Add comment · Show 4
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 syclamoth · Oct 14, 2011 at 06:18 AM 0
Share

What does your existing script do? It shouldn't be very hard to hack that to only affect one axis!

avatar image djfluffwug · Oct 14, 2011 at 07:28 AM 0
Share

It gets the velocity of the rigidbody and if it is over say, 5, it will then limit it to 5 but it does it for all axis.

avatar image djfluffwug · Oct 14, 2011 at 07:39 AM 0
Share

Oh don't worry. Figured it out :D

avatar image djfluffwug · Oct 14, 2011 at 07:49 AM 0
Share

Actually, I am not sure of how to do this.

if($$anonymous$$athf.Abs(rigidbody.velocity.y)>maxspeed) rigidbody.velocity.y=maxspeed;

That is the code I use. It limits the speed properly when going in one direction but if I go the negative direction it jerks due to the velocity being directly changed regardless of direction. How could I fix this?

2 Replies

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

Answer by chemicalvamp · Oct 14, 2011 at 02:23 PM

Checked and double checked this is working for me, and I took out what was unnecessary

using UnityEngine;

public class SlowFall : MonoBehaviour

{

 public float maxspeed = 1;
 public float speedreduction = 1;

 void Update()
 {
     Vector3 Adjustment = Vector3.zero;
     if (transform.rigidbody.velocity.y > maxspeed)
     {
         Adjustment.y += -speedreduction;
     }
     if (transform.rigidbody.velocity.y < -maxspeed)
     {
         Adjustment.y += speedreduction;
     }
     rigidbody.velocity += Adjustment;
 }

}

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 djfluffwug · Oct 18, 2011 at 12:59 AM 0
Share

Yeh that worked great! I don't know what was going wrong with $$anonymous$$e :/

Thanks for all the help!

avatar image
0

Answer by chemicalvamp · Oct 14, 2011 at 08:34 AM

 Well you could try reducing the amount your velocity is being affected. I think i would try
 
 if(Mathf.Abs(rigidbody.velocity.y) > maxspeed) (rigidbody.velocity.y = rigidbody.velocity.y - 3) 
 
 if(Mathf.Abs(rigidbody.velocity.y) < -maxspeed) (rigidbody.velocity.y = rigidbody.velocity.y + 3) 
 Find the magic number that arrests acceleration and your good to go.
Comment
Add comment · Show 10 · 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 djfluffwug · Oct 14, 2011 at 09:05 AM 0
Share

Tried that but when going in the negative direction it speeds off.

avatar image djfluffwug · Oct 14, 2011 at 09:06 AM 0
Share

Thanks though :D

avatar image chemicalvamp · Oct 14, 2011 at 11:23 AM 0
Share

it accelerates faster when traveling in a negative direction?

avatar image djfluffwug · Oct 14, 2011 at 12:10 PM 0
Share

Yep. For some reason, the speed goes really high when travelling in a negative direction even when using the script. It is strange.

avatar image djfluffwug · Oct 14, 2011 at 02:25 PM 1
Share

Thanks for trying though. All your help so far has been greatly appreciated!

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Limit Speed of a Rigidbody? 2 Answers

Cap rigid body move speed, without capping rotation speed 1 Answer

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

AddForce for spaceship acceleration, but with max speed 2 Answers

capping the speed of a rigidbody 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