# Need Better Physics Engine in Game

This topic is 2191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay, so this is my first Post, so please forgive me as I'm sure I won't be giving out enough information.

I've been working on a project for some time now, and I'm trying to create a better physics engine, however physics is not my best subject. My game is similar to minecraft, there are static chunk objects, and physics objects. My main problem is that it seems very laggy, compared to other games, even with high fps. So i'm wondering if I should be putting the physics step on a thread and just using the position data etc for the rendering in order to get better movement? Another problem is, how do I do rotational collisions? Here is some of my code for collisions.
[attachment=12348:townGen4.png]

// This is for when a physics object when it hits the bottom of a block (static position)
void collide(PVector loc_, float r_) {
...
if (checkTop(loc_,r_,r_,r_)){
vel.y*= -bounce;
loc.y = loc_.y + r_+h+teleport;
hasCollide = true;
} else if (checkBottom(loc_,r_,r_,r_)) {
vel.y *= -(bounce);
loc.y = loc_.y -r_-h-teleport;
hasCollide = true;
isOnGround = true;
if (vel.y > -0.7 && vel.y < 0.7 && inBlockID == 0) {
vel.y = 0;
}
...
}

boolean checkTop(PVector loc_, float w_, float h_, float d_) { // Check Y axis collision
if ( loc_.y + h_ > loc.y - h && loc_.y - h_ < loc.y - h && // Y top's edge is between Blocks borders
loc.x < loc_.x + w_ && loc.x > loc_.x - w_ &&
(loc.z < loc_.z + d_ && loc.z > loc_.z - d_) )
return true;
else return false;
}
boolean checkBottom(PVector loc_, float w_, float h_, float d_) {
if ( loc_.y - h_ < loc.y + h && loc_.y + h_ > loc.y + h &&
loc.x < loc_.x + w_ && loc.x > loc_.x - w_ &&
(loc.z < loc_.z + d_ && loc.z > loc_.z - d_) )
return true;
else return false;
}

Would I have to check all the points along a plane to see if it goes through another plane? as they would not be parralel. (The sides of an object)
Also is there a better way to make sure a physics object doesn't clip through the block, besides setting its location outside of it?
(loc.y = loc_.y + r_+h+teleport;)

##### Share on other sites
Yeah i've seen some of them libraries before, they look amazing, but i'de prefer to implement my own, for the experience mostly. I guess i'll have to search more for examples or explanations on how to implement a simple version of bullet physics.

Im going for something like this:

I just need to get a better way to do collisions.

##### Share on other sites
My goal does not involve using a physics engine, it involves building one. Game development is a hobby of mine, the features of a physics engine I need are not so far out of my grasp. I will find the answer if I spend more time on it. I'm a uni student after all with much free time. I've got experience in robotics too, so a physics engine also interests me. However I will try out some of the recommended physics engines in the mean time.

Regarding your suggestion of getting my game out there, what is the best way to go about this? I'm guessing releasing a playable version online somewhere, have you done this before?

##### Share on other sites
Fair enough

Releasing and publishing a game is a completely different subject, and I can't say I'm really experienced in that matter, there are however systems such as steam greenlight which can help you with getting your game published for a very reasonable fee. I'm mainly a graphics and gameplay programmer (and CS and former engineering student) myself, things like publishing and legal matters I leave to my business partner who's qualified to handle those things.

##### Share on other sites
Hi,
I've been writing my own "physics engine" as well, though it's 2D. You might want to have a look at euclideanspace.com as well as this paper.
The paper is essentially an overview of everything you need in a physics engine. I hope his helps to get you started

Edit: And btw, as long as you're not very versed in the involved math and physics as well as general algorithm design it will be quite hard to get results like the stuff in the video you posted. It gets really hairy in the details. But even if you don't get to that point you'll learn a lot on the way and that seems to be what you're going for anyway. Edited by bonus.2113

##### Share on other sites
Wow great links, they seem like just what I was looking for. I am well in it for the learning experience as well. 2D physics are very similar to 3D, my first 3D physics simulations were based directly off 2D. There is a lot of maths involved with getting the camera to work in opengl, it's possible, just hard haha. I was mostly working on data structures, loading on threads and world generation techniques before, and my physics engine (which I neglected) was based on older version off a 2d version of Daniel shiffman's physics examples I got my hands on in first year uni, something similar too:
http://natureofcode.com/book/chapter-2-forces/

Ahh okay, I'll look into steam greenlight for publishing. Atm though I'm mainly interested in having my game on a site, so people could possibly beta test it, have you done this before? I also have a bunch of questions about graphics programming, I'm using VBO's for the cubes, trying to implement a simple light shader, or the reflective water like in Terasology!

Well it seems I have a long and interesting road ahead. If I have any more questions I'll post them thanks for all the help!!

##### Share on other sites
Another tip, if you want to learn how a physics engine works, is to look at the source code for any of the available ones. I find Bullets code reasonably easy-to-read.

I'd also like to point out that even if your final goal is to write your own, you will still learn a lot about physics engines and whats needed to make it stable, by using an available one first.

I think most people who set out on doing physics underestimate how much work (and stuff to learn) it is to just get a ready-made physics engine to do exactly what you want it to, unless you are just doing very simple destruction/explosion-like physics.

It's very far from a waste of time. You will need all those parts in your own engine too, and if you are versed in using them, it makes it a lot easier to debug your own later. Edited by Olof Hedman

##### Share on other sites
Do you need the blocks to rotate? For a voxel based game, i think non-rotating cubes would be better because:
1.They fit in holes, if you rotate a cube you cant fit it anywhere because its never aligned right
2.Simpler for you to implement
3.Faster physics?

Though if you want to have objects that are not 1-cube-sized, it might not work that well. But for non-rotating multi-voxel objects, you could make big sliding doors out of them or something, which might be buggy with rotation...

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633385
• Total Posts
3011601
• ### Who's Online (See full list)

There are no registered users currently online

×