Ok guys here is my problem.I am using this script to calculate my mph speed
But when i get my vehicle up to around 80 it freaks out and behaves weird so im just gonna make an illusion of doing 80.I need to know how instead of calculating miles per hour i can do some smaller then miles like feet maybe.What im wanting to do is when your doing 40 mph the speedo and script displays you doing 80.
That way i can keep my vehicle behaving how i need but trick the player to thinking they are doing 80.
Just have the speedometer display myObject.rigidbody.velocity.magnitude*2 or something.
Also you should note that rigidbody.velocity is not in miles/hour. It is in units/second. By "units" I mean Unity's units. This could be meters, miles, feet, whatever... It depends on how large your models are.
Some games (notably Grand Theft Auto) uses techniques to make it look like you are going faster when you really aren't. Increasing the FOV (field of view of the camera) can make it look like you are moving faster. In GTA they also make the other cars move slower so it feels like you are moving faster.
@Tyler - You are aware that "rigidbody.velocity.magnitude" does not result in speed in miles per hour, right? I believe the result is in meters per second by default, which you'll need to convert if you want mph.
I could be wrong, but the way I understand it the default for all physics is in metric units: meters, kilograms, and m/sec. It should be easy enough to build a test to confirm it. If I get a chance tomorrow I might try to do just that.
Sounds good bigk!So i see that right now im already where i want to be by what pak says.Because my truck behaves fine at 40 but not 80 but sence this is in meters that means when im doing 40 meters im doing 80 miles!So its pretty much already where i need it but see what you can come up with bigk!
It's not in metric, the units are completely undefined. AFAIK the only metric constant in Unity is Physics.gravity which is in m/s^2... but of course you can change gravity to whatever you like.
I personally define units as meters, so when I make/import a model I can scale it to that size. It makes physics calculations a lot easier as most physical constants and relationships are metric.
Well I completely agree that using meters as your unit is the way to go. I debated this very point in another thread where others were arguing the opposite (that you could choose any arbitrary measure, like the length of your hand or something). In that thread I had to concede that using meters in a game of microscopic or planetary scale wouldn't make much sense, especially because gravity and other simple physics equations give way to more complex relationships at such scales.That's what we've been told, but one would have to believe that it's not entirely true. Assuming the physic's gravity standard is 9.8 m/s**2, then how could you use, for example, "feet" for a distance standard and still have accurate physics simulation? Mathematically it's not possible. Although UT has said that you can use any measurement standard you want, they have also said that in order to maintain physics accuracy you should use meters as your distance standard. Thus my assumption that rigidbody.velocity.magnitude is measured in meters per second. I'm assuming this because I haven't read anything (from UT or PhysX) to the contrary.
And in response to your question about having accurate physics simulation if you use feet as your units. It's still possible, you just have to change the gravity constant to feet per second. Physics.gravity = 9.8*Vector3.down*feetPerMeter;
The way to understand this is to note that the mathematical relationships (ie, the formulae) between force, acceleration, mass and velocity are the same regardless of the units used. For example, the relationship
...is valid regardless of the units of mass and acceleration you use and indeed the units of force will be determined by them. So, if you use pennyweights for mass and furlongs per fortnight squared for acceleration then the units of force will be pennyweight furlongs per fortnight squared. (Amazingly, Google can actually convert pennyweight furlongs per fortnight squared into newtons for you if you ask nicelyCode:
- Force = Mass x Acceleration
The units of mass and distance in Unity are arbitrary, so you can't say what speed you are "really" going at. However, by default, the time unit corresponds directly to seconds of real time and the gravitational acceleration is 9.8. Since Earth's gravity is nominally 9.8 m/s^2, this means that Unity's default gravity corresponds to Earth gravity if you regard Unity's distance units as metres.
There isn't any datum constant in Unity to set the value of mass so the units of mass and force are still arbitrary. However, it is probably easiest to maintain consistency if you think of the mass as kilograms and the forces as newtons.
I'm wired to the world... that's how I... know... everything...
Ok, now I'm completely confused. :P
If gravity in Unity is set to 9.8 (which corresponds to 9.8 m/s**2, a known constant) then doesn't rigidbody.velocity.magnitude show speed/velocity in m/sec? If it doesn't, then of what use is it and how do we find velocity?
If your models correspond to 1 unit = 1 meter, than indeed rigidbody.velocity is "in" meters per second....
Keep in mind that Physics.gravity is not really in meters/second^2, it represents units/second^2. It just happens that Earth's gravitational pull is 9.8m/s^2, so if you want to use feet or furlongs everywhere you'll need to convert this constant into your units.
Last edited by Antitheory; 03-01-2011 at 09:36 AM.
@Antitheory - Ok, we're on the same page then. So for all intents and purposes, for the average user who doesn't edit the gravity settings, they should assume rigidbody.velocity is in m/sec which was my original answer.
Ok so size matters! So how can we calculate velocity no matter the size of the vehicle like real world. Or should we just do our best to keep everything on a certain scale and then just work from their with what unity already provides.
if you are doing 'realistic' stuff, like a racing game or your average FPS, the easiest thing to do is go with 1 unit = 1 meter. This is the default assumption that unity physics make. So, if you want to build an average sized human, make him 1.7 units tall in Unity, equivalent to 1.7 meters tall in real life. Then velocity is in meter per second
If you are doing 'realistic' stuff in space or at a microscopic level, then consider thinking of the world as 1 unit = 1 mm, 1 nm, or 1 km, as appropriate. You'll want to adjust default physics gravity, and possibly some other stuff.
If you are making a non-realistic game, such as Little Big Planet, I'd think of your your scale so that your characters are 1 (or maybe 2) units tall. Then you can think of speed as 'character heights per second'.
IMHO avoid english measure (pounds, slugs, feet) as you will soon go batty. And I'm saying that as an someone who likes miles and inches, just not for math.
//edit when i say avoid englush measure, I mean for your world scale and game math. It's no problem to display MPH in the gui by simply multiplying your game meters/sec number by the right scaling factor.
Last edited by pakfront; 03-02-2011 at 11:36 AM.