Hey guys,
Is there a way to get the X and Y velocities and convert them to an always-positive number? I can’t seem to find a way to do this, please help.
Thanks,
-Ember.Y
Hey guys,
Is there a way to get the X and Y velocities and convert them to an always-positive number? I can’t seem to find a way to do this, please help.
Thanks,
-Ember.Y
You have to take the absolute value of the number and it will turn every number positive.
In an equation it looks like |x|, but I don’t know the equation for the expression behavior.
It’s like math.abs(x) or something like that. It may be wrong, but I’m sure Galactian or JR01 would know more on it than I would.
I make it super complicated such as using a filter to see if the value is less than 0 and then have it multiply by -1 so should always be positive. I don’t recommend this way, but I’ve done it before when I couldn’t remember the equation.
I have a good idea, that is eisier… just a sec…
Well, MP’s worked, thanks though!
how calculators do it:
Math.sqrt(Math.pow(A,2))
Basicly just squaring which turns it positive, then square rooting, which turns back to origianal number, but positive.
I also have an example of a speedometer that uses both x and y velocities.
It is a nice example! But if you run into a wall, and the velocity is still going in the player movement, then the speed does not change to 0.
Thanks! I’ve put this into my game, and it works great! Also, I added a circular speed-o-meter, like shown on some cars:
You could make the arm on the gauge red or a more brighter color so it’s more easier to see. Since it blends in with the ticks on the speedometer. At least on most vehicles, it’s a brighter color or neon.
Its better with a motor,
Velocity is a contstant speed so when you use Velocity even into a wall, it will extract the value its trying to move at the speed at.
Is there a good equation to use position instead?