A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Hot answers tagged

4

The issue was that the radius that I inputted into the CircleCast was not accurate. Initially, I set the radius to that of the cueball's circlecollider2D, which would be .09f. But since I lowered the transform scale of the ball from 1 to .8f, that radius was no longer accurate. To get the accurate radius in code, you get either the the x or y value of its ...


2

An assertion failure happens when the expression returns 0, in this case when m_bodyCount is lower or equal to 0. This means that, whenever your code executes b2World::DestroyBody();, all the previously created b2Bodys are already destroyed, if there ever were any created in the first place. If you did create at least one (1) b2Body* instance, make sure ...


1

Typically the fixtures would approximate the shape of the sprite, they're locked to the body and won't change their transformation. So you just draw the sprite with the body's transformation (position/rotation), and don't care about individual fixtures. If you really need to draw the fixtures, see the b2World::DrawDebugData() method implementation. It uses ...


1

Getting two physics systems to do exactly the same thing is a very difficult problem that requires having the physics simulations be entirely deterministic. Even incredibly tiny differences between the two will accumulate into wildly different outcomes given time. Searching about Box2D determinism it seems that you can't count on that in this case due to ...


1

This caution box is telling you to not base your physics simulation on pixels. The pixels your game will be able to show will not be the same across all device, and is not a reliable measure to have your game consistent. What it suggests is that you use "real world" sized objects in your simulation, and use your rendering engine to display the simulation. ...


1

Problem solved: the error was in drawing the boxes all along. The way Box2D returns positions is by returning the center of an object, and not the upper-left corner. So all I had to do was deduct half the width and height from my texture's position to draw it in the right spot. m_bounds.x = m_body->GetPosition().x * World::PPM; m_bounds.y = ...


1

I was under the wrong impression that the default filter for libgdx is Linear Filtering, so I never actually tried setting it manually. Setting it for the texture solved it for me. beachTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);


1

The KEYDOWN event is fired every time the key is pressed down, so the impulse is applied only then. Instead, you should remember the state of the key and apply force in every iteration of the main loop if the key is pressed down. See this article for example code: https://www.iforce2d.net/b2dtut/forces Also to make sure the speed is framerate-independent, ...


Only top voted, non community-wiki answers of a minimum length are eligible