Jump to content

  • Log In with Google      Sign In   
  • Create Account


Need Better Physics Engine in Game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 Deus00   Members   -  Reputation: 125

Like
0Likes
Like

Posted 17 November 2012 - 05:07 AM

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.
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;)

Attached Thumbnails

  • beastly.png


Sponsor:

#2 Radikalizm   Crossbones+   -  Reputation: 2771

Like
6Likes
Like

Posted 17 November 2012 - 06:12 AM

Is there a specific reason you want to write the physics engine yourself?
It's quite difficult to write an efficient and fast physics implementation, so you might want to consider using a (free) proven solution.

Some popular solutions include: Havok (free for games with a retail price of $10 or lower), bullet physics, nvidia physx and ODE (haven't heard about this one for a while though)

I'm sure any of these can fulfill all of your physics needs, and more.

If you insist on writing it yourself I'm afraid I can't really help you out here.

#3 Deus00   Members   -  Reputation: 125

Like
0Likes
Like

Posted 17 November 2012 - 10:46 AM

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.

#4 Radikalizm   Crossbones+   -  Reputation: 2771

Like
6Likes
Like

Posted 17 November 2012 - 11:05 AM

I'd personally recommend against trying to build a full-featured physics engine on your own if your actual intention is to build a game. You can expect to dedicate quite some time to writing something which can qualify as a "simple version" of bullet, and I'd assume that time would be better spent on trying to get your game out there.

Bullet itself has been in development for years and its main author, Erwin Coumans, has been a senior physics engineer at multiple companies, including Havok if I remember correctly, so it has taken quite some time even for a very experienced engineer to develop something usable.


Now of course, if your main goal is to actually build a physics engine you should just go for it, but seeing your original post I don't think this is really what you want to accomplish in the end, right?

It's also interesting to note that a lot of major AAA studios who build their own game engines don't even bother with writing their own physics engines anymore, and just use existing solutions like the ones mentioned in my previous post.

Edited by Radikalizm, 17 November 2012 - 11:06 AM.


#5 Deus00   Members   -  Reputation: 125

Like
0Likes
Like

Posted 17 November 2012 - 12:33 PM

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?

#6 Radikalizm   Crossbones+   -  Reputation: 2771

Like
1Likes
Like

Posted 17 November 2012 - 01:06 PM

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.

#7 bonus.2113   Members   -  Reputation: 630

Like
3Likes
Like

Posted 17 November 2012 - 03:20 PM

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, 17 November 2012 - 03:27 PM.


#8 Deus00   Members   -  Reputation: 125

Like
0Likes
Like

Posted 18 November 2012 - 03:39 AM

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 :D thanks for all the help!!

#9 Olof Hedman   Crossbones+   -  Reputation: 2647

Like
3Likes
Like

Posted 18 November 2012 - 04:30 AM

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, 18 November 2012 - 04:42 AM.


#10 Waterlimon   Crossbones+   -  Reputation: 2356

Like
1Likes
Like

Posted 18 November 2012 - 04:55 AM

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...

Waterlimon (imagine this is handwritten please)


#11 Steve_Segreto   Crossbones+   -  Reputation: 1468

Like
0Likes
Like

Posted 18 November 2012 - 05:52 PM

I 2nd Radikalizim ... any time you spend writing your own physic "engine" or even just rigid body physics routines is a waste, just use bullet physics and get the job done. You can override any of the bullet callbacks/solvers and have your own custom implementations.

#12 Deus00   Members   -  Reputation: 125

Like
0Likes
Like

Posted 19 November 2012 - 12:57 AM

I need rotational collisions for skeleton/body physics, and also it's alot better if the cubes rotate... And yes Olof, i've read alot so far, and I realize there is alot of work that goes into physics engines, but I find if I make my own engine, it is easier for me to debug and modify. I know how versatile they are to use, but I don't think I need to implement all the features they have. The example i've looked at uses points and tests them in a feild, i'm not sure exactly because the dependencies are a little confusing, but im guessing the way to check basically would be to check all the points on a plane go through another plane? This mathematically makes sense, but would take alot more processing power.

http://www.openprocessing.org/sketch/39230

#13 Olof Hedman   Crossbones+   -  Reputation: 2647

Like
1Likes
Like

Posted 19 November 2012 - 02:19 AM

I wasn't saying anything about the work going into the physics engine, I just said there is a non-trivial amount of work _using_ any physics engine, and that you can learn a lot from it that is useful when you make your own. And most are very modular, so you can use for example the collision detection part of it, and implement your own physics, and thus take it one problem at a time.

There is a certain pride in feeling you have control over _all_ the code in your project, so I totally understand your wish to roll your own :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS