Skip to main content

Questions tagged [floating-point]

Floating point numbers are approximations of real numbers that use a form of scientific notation to store significant figures and an exponent. Use this tag for questions that pertain to the use of floating point numbers in games.

Filter by
Sorted by
Tagged with
0 votes
0 answers
81 views

How can I improve vector collision algorithm?

I'm making a game (shocker) in pygame and had issues with tile-based collision detection. There are 5 different non-empty tile types (pictured below) which can be rotated in increments of 90 degrees ...
Sad Robot's user avatar
0 votes
0 answers
80 views

How to make calculating the inverse matrix more robust?

When I calculated the inverse matrix, I found that the error in using the float data type would cause the inverse matrix calculation error. Is there any good solution? ...
noodle_run's user avatar
0 votes
2 answers
151 views

Is there a logical reason for SFML's Vector2 being templated?

The game development library SFML has a Vector2 class template (and a Vector3 for that matter), which can use any arithmetic ...
JensB's user avatar
  • 157
1 vote
1 answer
411 views

Godot Velocity: Invalid type in utility function "lerp", cannot convert arg 2 from Vector2 to float on line 40

I'm trying to solve a lerp problem on my velocity, searched some stuff here and there, but found nothing that solved it. Can you help me? ...
Murilo Melo's user avatar
0 votes
2 answers
168 views

How can I make a reliable time-based object updating system?

So an object has a position, velocity, and is affected by gravity. ...
CPlus's user avatar
  • 143
1 vote
2 answers
155 views

What dynamic range of numbers do games typically use?

Most of the numeric quantities used in games (aside from integers for counting or indexing objects) are single-precision floating point. This is IEEE format, which allows for numbers as big as 1e38 ...
rwallace's user avatar
  • 125
0 votes
1 answer
793 views

24bit float to RGB

There's solutions to convert float to RGBA but I would like to encode a float depth value in RGB format and save the three components in three separated unused alpha channels and recompose when needed....
philB's user avatar
  • 159
0 votes
1 answer
2k views

Dealing with Floating Point precision in a Minecraft-like game

As far as I know, you can walk for 30 million meters in either direction in Minecraft to reach the end of the world. My question is, how does Minecraft handle loss of precision when dealing with ...
Moons's user avatar
  • 103
6 votes
3 answers
3k views

Convert integer to float while also dividing down the scale, without data loss

I'm working on a game, and my intent is to avoid use of floating point for unit positions. To that end, I'm using 32-bit integers for all positions, with a millimeter scale. However, for rendering, I ...
Nairou's user avatar
  • 614
3 votes
2 answers
4k views

Mathf.Approximately: should I use it & for what cases?

For comparing floats they recommend using Mathf.Approximately At the same time, they don't use it, for example, for comparing types such as vectors. From Vector3....
Serg's user avatar
  • 383
1 vote
6 answers
644 views

How to deal with players having too much money (or any large numbers)?

I'm working on a browser MMORPG in PHP and MySQL and today got a bug report about int32 overflow, due to the player having too much money. When I was designing the core system, I completely forgot ...
matronator's user avatar
3 votes
0 answers
164 views

Quake 1: frame timer

If you check Quake 1 source code (sys_linux.c), you can see something like this: ...
user1095108's user avatar
51 votes
6 answers
18k views

How can I perform a deterministic physics simulation?

I'm creating a physics game involving rigid bodies in which players move pieces and parts to solve a puzzle/map. A hugely important aspect of the game is that when players start a simulation, it runs ...
jvn91173's user avatar
  • 614
0 votes
1 answer
211 views

How can I avoid the precision loss when recentering objects on open terrain?

For a better context this question is related to this one: What's the largest "relative" level I can make using float? When the player is moving too far away from the center, all the ...
jokoon's user avatar
  • 5,253
2 votes
1 answer
194 views

How much slower is it to draw on "half pixels"?

I've noticed that games like Diep.io are using floating decimal points for thin stroke lines on the grid. I have even tried this myself, by adding 0.5 to all of the ...
Jacob Gunther's user avatar
0 votes
1 answer
2k views

HLSL float bitfield

In HLSL I want to store a bitfield for each color in a texture. Specifically spanning 3 floats (RGB, not alpha). Since each float has to be between 0 and 1 I can only use the significand/mantissa of ...
Martin's user avatar
  • 43
8 votes
1 answer
4k views

Why loss of floating point precision makes rendered objects vibrate?

I'm working on an open-world game. I noticed glitches when I move far away from the origin. The objects seem to be shaking or wiggle. Especially the z-fighting seems to wiggle. And the objects that ...
Newline's user avatar
  • 183
1 vote
1 answer
297 views

Saving total play time could be fine?

I'm making a game that needs to save total played time into file (using JSON) for comparing & resolving data conflicts between local and cloud. I will override outdated one. Currently, I'm just ...
modernator's user avatar
  • 1,223
2 votes
2 answers
2k views

Prevent tile layout gaps

I'm making a map viewer where you can specify where tiles go in a map and then see it on the screen, translate it, and zoom in and out. Here's a picture showing the tiles used to make my example map ...
Ryan1729's user avatar
  • 724
1 vote
2 answers
2k views

Setting a uniform float in a fragment shader results in strange values, is this a type conversion? How can it be fixed?

First, some details: I'm learning OpenGL from the tutorials on https://open.gl My computer is running Linux Mint 18.1 Xfce 64-bit My graphics card is a GeForce GTX 960M OpenGL Version: 4.5.0 NVIDIA ...
Faison Zutavern's user avatar
4 votes
0 answers
195 views

How can I render geometry represented in a 64-bit floating point environment?

In this video about Star Citizen, right at the 12:30 mark on the timeline you can see the player zooming in on a space station who's location is clearly out of the limit of 32-bit floating point ...
Allahjane's user avatar
  • 719
5 votes
5 answers
4k views

Are very long floating point numbers a problem?

Very simple question, but important: I was using a floating point number ('float') in C++ to handle movement speed, and it suddenly ran crazy. It turns out the speed increased very fast to ...
Henry Stone's user avatar
0 votes
2 answers
287 views

Float inaccuracy. libgdx only? java only? also why?

Hey all I have just come to notice that floats are not accurate even when they are explicitly set and unchanged. For example i have some basic code running and it is: ...
Big T Larrity's user avatar
1 vote
0 answers
49 views

Fallback for R32F alpha blending

I'm rendering an aggregation of value into an R32F format texture, using alpha blending to accomplish the sum operation. R32F alpha blending is not supported on all hardware. What kind of fallback ...
Zachary Burns's user avatar
21 votes
3 answers
4k views

Non-integer speed values - is there a cleaner way to do this?

Often I will want to use a speed value such as 2.5 for moving my character in a pixel-based game. Collision detection will generally be more difficult if I do that, though. So I end up doing something ...
Accumulator's user avatar
5 votes
1 answer
3k views

Why aren't there game and physics engines with double precision?

Choice of game design and other human psychological factors aside is the present hardware not capable of working with double precision floating point calculations with reasonable performance? It can ...
Allahjane's user avatar
  • 719
0 votes
2 answers
204 views

Unity, positioning with ints instead of floats

I round my transform.position to the nearest integer at the end of every frame so it's never a decimal number. I would like to know if there's a way to make unity store the position in ints instead of ...
user avatar
1 vote
0 answers
250 views

Precision problems with realistically scaled planets/terrains [duplicate]

Recently I've been working on a realistically scaled planet engine. I found several interesting links about how to do it, what problems will come up after, and how to solve them. The approach I took ...
Aulaulz's user avatar
  • 249
17 votes
1 answer
7k views

In Unreal, what are the differences between C++'s float and FFloat32?

I have been trying to learn some deeper aspects of UE4 and while reading many examples codes and also the source base of the engine, I noticed that sometimes people (and the very source code) use the ...
Kim Shutter's user avatar
2 votes
1 answer
352 views

Simulating elastic ball collisions quickly escalates to disaster

I'm trying to learn HTML canvas and was working on a basic physical simulation, where a number of balls are drawn and set in motion, and the program simulates them colliding and bouncing off the walls ...
momotaro's user avatar
1 vote
0 answers
577 views

Handle floating point precision errors in collision detection and resolution

I am experimenting with a continuous collision detection and response of points on a tile map. This are my results for now: I did this by shooting a ray (red line) from the current position (red ...
Michael's user avatar
  • 111
1 vote
1 answer
382 views

Floating point determinism with respect to procedural generation, clustering and GPU offloading

I've been designing a distributed procedural generation system for a while now in my spare time and one of the problem's I've been thinking about recently, with respect to the broader architecture, is ...
Nathan Ridley's user avatar
6 votes
1 answer
2k views

How do I avoid floating point indeterminism when implementing lockstep?

I am working on a multiplayer RTS game in Java. It uses lockstep for networking, which requires that both computers can deterministically. These are the 2 closest/more viable approaches I could come ...
Daniel's user avatar
  • 61
7 votes
1 answer
1k views

Why don't objects far away from the camera experience floating point issues?

In Kerbal Space Program, a space exploration game made with Unity, Floating origin technique is used to overcome the floating point precision issues. While in map view, the world (a scaled space with ...
Maks Maisak's user avatar
1 vote
1 answer
1k views

WebGL half float equivelant?

I'm trying to find a half float for the purposes of doing math in a fragment shader, not trying to have a half float texture. Is there an equivalent of the ...
Alan Wolfe's user avatar
  • 2,363
2 votes
1 answer
660 views

How can I deal with vertex precision errors between terrain chunks?

I am using OpenGL to render the following scene, using vertex data from one of the map files of a popular MMORPG. The data is chunked and the pictured scene is made up of 256 (16x16) chunks. However ...
Alan's user avatar
  • 23
2 votes
2 answers
1k views

Getting around limitations posed by float in space game

I'm working on a procedurally generated game set in outer space. As in the real world, the game universe will be pretty much 99% empty, with planets/stars/solar systems etc... being very far apart. ...
Entity's user avatar
  • 601
5 votes
1 answer
1k views

How do I deal with floating-point error given a far-away camera?

Whenever a camera is "far" away (its location is some "large" vector), trouble arises when rendering objects close to it: It is the classic precision loss from subtracting 2 floating point numbers. I ...
user1095108's user avatar
15 votes
6 answers
14k views

How do I generalise Bresenham's line algorithm to floating-point endpoints?

I'm trying to combine two things. I'm writing a game and I need to determine the grid squares lying on a line with the floating-point endpoints. Moreover I need it to include all the grid squares it ...
SmartK8's user avatar
  • 614
2 votes
1 answer
188 views

how did coordinate-handling in old flightsimulators work?

Im currently working on a combat flight simulator pure for own fun. Using a floating-origin i thought the float inprecision was history, however this was the case untill i tried adding multiplayer to ...
stephan's user avatar
  • 33
2 votes
2 answers
2k views

How can I simplify this code to compute the shortest rotation between two angles?

The following code will find the shortest rotation (in radians) (from pi to -pi) that I need to apply to from to leave me with to...
t123's user avatar
  • 713
16 votes
3 answers
4k views

What's the largest "relative" level I can make using float?

Just like it was demonstrated with games like dungeon siege and KSP, a large enough level will start to have glitches because of how floating point works. You can't add 1e-20 to 1e20 without losing ...
jokoon's user avatar
  • 5,253
5 votes
4 answers
5k views

How to reset the world in an infinite runner game to prevent an overflowing float?

Im following Mike Geig's 2D infinite runner tutorial. However, I'm seeing a potential problem of overflowing the float How can I reset all objects and camera back again to the origin? The approach I'...
Michael Buen's user avatar
1 vote
1 answer
728 views

Point rotation around point, accuracy question

I study OpenGL ES 2.0. But I think it's more a C++ question rather then an OpenGL one. I am stuck with the following rotation question: It is known, that rotation transformation can be applied using ...
Alex Hoppus's user avatar
4 votes
1 answer
1k views

Deterministic calculation in JavaScript [closed]

I want to create a multiplayer game with HTML/JavaScript and only send user input between players. I read some articles for C++, saying that I could not expect floating point to get the same results ...
cnubidu's user avatar
  • 41
0 votes
2 answers
148 views

Algorithmic error in tile engine? [closed]

I'm toying with creating a tile-based 2D java game engine. I can render the "local" area without issues(I.E. deciding which local tiles to render). The problem came when I introduced floating point ...
Daniel Way's user avatar
0 votes
1 answer
278 views

XNA Float values don't work as parameter

With the Microsoft XNA Framework I can change the color of a tinted texture by changing it's integer values like so: ...
Anthonʎ's user avatar
3 votes
1 answer
457 views

Continuous world and very large levels: going around the FPU limitations with Ogre3D

I'm currently using Ogre3D, and I'm wondering is it's possible to have a very large level (hundreds of kilometers) using the right scenemanager. Storing or having the level is not a problem, since I ...
jokoon's user avatar
  • 5,253
0 votes
1 answer
674 views

Issues calculating frame independent movement

I'm developing a Breakout style game in C++ using SDL. The problem so far is that the ball slows down and speeds up for no particular reason. The slowdowns usually last a few seconds. EDIT : When ...
olevegard's user avatar
  • 172
15 votes
3 answers
2k views

What caused "falling out of the world" and what fixed it?

A lot of early 3D games had the problem where you'd be trundling merrily along and suddenly everything was black, with an island of what looked like the hollow facade shell of the scene you'd been ...
chaos's user avatar
  • 3,135