- Home /
Unity limiting max velocity on Rigidbody?
Hi all,
I've made a scene (2d) with walls (rigidbody2d + boxcolliders2d) - top, down, bottom, left - and a quad moving with an horizontal velocity (there's no Y component).
I got an script attached to the quad:
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
// Use this for initialization
void Start () {
rigidbody2D.velocity = new Vector2(1000f, 0f);
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
Debug.Log(rigidbody2D.velocity);
}
}
But, the quad moves really slow and the console shows that the rigidbody's X velocity is always 100f (at max) after the initial 1000f set in Start().
I can't get it any faster. Why is that?
Thanks!
PLEASE can someone from unity explain this? i have the same problem and it severely limits my game.
Thanks
Hello @CleanCut, no I didn't get any word from Unity. I opened a bug report for this just to now if it's a bug or an expected behaviour but so far nothing. I got a solution (maybe a band-aid solution). As some fellows have said, try downsizing your scale. I'm using it 10x smaller now and so, my max velocity now is 10x faster. I didn't expected that would do a big difference in physics, but now everything works just fine. Every collision works as expected, even when the ball is too fast to play. So, for now, try that. Down the scale of everything: size of camera and objects. $$anonymous$$aybe that will work for you too.
Thanks @haqqaton, I'll try that. Did you scale down by changing the sprite's pixel-to-units, changing the scale on the transform, or both?
Hi @CleanCut, my game doesn't have any sprites (only polygons) so I've changed the transform scale only.
@haqqaton - Thanks. Since I wanted to go about 2.5 faster than the limit, I decreased my transform scale on everything by 10 times ((0.1, 0.1, 0.1) ins$$anonymous$$d of (1, 1, 1)) to end up with some headroom in case I want to go even faster. This still seems like an unreasonably low limit for a physics system, but at least I can make it work now.
Answer by Balint · Nov 17, 2013 at 04:08 PM
This is'n an exact answer, but maybe could help. Go to edit, project settings, physics2d. Maybe there you can find the problem. (I have similar problems in 3d, here could I solve them.) Be sure to check other menus in the project settings, (i.e.: Graphics). Lot of problems hides the sollution here.
Thanks Balint, but I couldn't find anything that might help there.
Answer by sattri99 · Dec 31, 2013 at 03:04 PM
If you want to Limit the maximum Velocity of A 2dRigidbody you can apply the following script
var max : Vector2; //here you can assign your maximum values for limiting velocity for both x and y
function Update () { //this line checks whether the rigidbody exceeded the maximum velocity, and if it is,then limit it to maximum velocity if (rigidbody2d.velocity.x > max.x) rigidbody2d.velocity.x = max.x; //this is the same for y axis if (rigidbody2d.velocity.x > max.x) rigidbody2d.velocity.x = max.x;
This is how it is done. I hope you will find it useful
Not really useful for dealing with the system-imposed maximum velocity. This question is about stopping the system from imposing a max velocity upon you.
This was not so really bad that you have voted it down please take your vote and i will delete the answer
I don't have sufficient reputation to cast downvotes yet.
The answer has nothing to do with the question and doesn't answer it. Either convert it to a comment or delete it
Answer by Twice-Circled · Nov 22, 2013 at 12:22 AM
I have the exact same issue, very strange. One way around it is to continue to use Rigidbody (as in the 3D version), it doesn't seem to have the same limitation.
Can anyone from Unity shed some light on this? To restate the issue, the linear velocity of Rigidbody2D seems to be capped at 100.0.
Answer by Lev-Lukomskyi · Nov 25, 2013 at 03:00 PM
I have the same issue. Another solution is to set bigger «Pixels to Unit» property (eg. 100) for all sprites and decrease camera size.
Thanks Lukomskyi, but I ain't not using sprites. $$anonymous$$y game is made just with polygons. That quad scale is (10, 10, 1) while camera is like the image. Do I need to worry about the scale? Do you still think that it may be the problem? Thanks!
It appears that 2d physics engines don`t like big numbers for velocity. For example in Box2D there is limit 2 units per step - see here: http://www.iforce2d.net/b2dtut/gotchas
Thanks Lukomskyi, I have scaled down my polygons and so the velocity has "increased" to the point it's ok for my purpose. I'll use it this way for now, but I send a message to Unity to see if it's the expected behavior (be capped). Waiting for an answer there.
Answer by rxninja · Nov 25, 2013 at 11:48 PM
The 2D physics engine is strongly tied to scale. When using sprites, adjust the pixels per unit in order to get your objects down to a scale of 1. At that scale, nothing should ever need to go faster than 100 units/second, as that would pretty much teleport them across the screen instantly.
I ran into this same problem. I was using very high-res sprites and trying to work at a much larger scale (large camera size to compensate for large objects). Everything was moving super slow and it was obnoxious, but getting the PPU right fixed everything. If you don't do that, you'll start to also have trouble with forces, too.
Hi @rxninja, thank you for replying. Could you read my reply to Lukomskyi? Do you still think that the scale may be the problem? Thanks!
Your answer
Follow this Question
Related Questions
Keeping momentum with rigid bodies. 0 Answers
Stoping Velocity Breaks Script [Solved] 0 Answers
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Slow a rigidbody to a stop over a set distance? 1 Answer
How do i add a boost in velocity to a 2D ball when you press it? 1 Answer