• Velocity of a Player
    7 replies, posted
I want to make a HUD with velocity of the Player. But in Gmod Wiki I cant Find anything which Gets the Player Speed(for Deathrun). Is there anything or not? If yes pls tell me
Player:GetAbsVelocity. Returns a vector, so you'll have to take the length
[ERROR] lua/includes/extensions/math.lua:160: bad argument #2 to '__add' (Vector expected, got number) 1. __add - [C]:-1 2. Round - lua/includes/extensions/math.lua:160 3. RoundedBox - lua/includes/modules/draw.lua:189 4. v - lua/test.lua:30 5. unknown - lua/includes/modules/hook.lua:84 What did I wrong? [editline]11th January 2017[/editline] Ok I found the Solution: GetVelocity():Length2D() [editline]11th January 2017[/editline] New Problem: There is not showing 400... It is showing 400.00516946549874984
Use Length and not Length2D since it will not take into account the z velocity. Also, math.floor the result.
[QUOTE=code_gs;51656092]Use Length and not Length2D since it will not take into account the z velocity. Also, math.floor the result.[/QUOTE] What's the point of using math.floor?
[QUOTE=txike;51656143]What's the point of using math.floor?[/QUOTE] It will round the number down to the nearest whole number, basically getting rid of that long string of decimals at the end.
[QUOTE=pqbrown;51656210]It will round the number down to the nearest whole number, basically getting rid of that long string of decimals at the end.[/QUOTE] math.floor works, but if he wanted to be as accurate as he could, math.Round would be more precise.
[QUOTE=xbeastguyx;51656972]math.floor works, but if he wanted to be as accurate as he could, math.Round would be more precise.[/QUOTE] It's standard practice to floor speeds in programming and physics to my knowledge. Think of it like a float to int casting.
Sorry, you need to Log In to post a reply to this thread.