Easy physics usage

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Easy physics usage

Post by B@z »

Hi
As others said in this forum, we shouldn't use irrlicht's collision system, coz its slow, and not accurate.

So my questions:
1) what physics engine should i use, if i only want to make objects collide (only players and mobs with map and each other), so not rotating when colliding, no forces, etc. the best would be like irrlicht getCollisionResultPosition function. i give the selectors, the geometry, and the current position, and ellipse, and it gives back a position where should the model be. so i have the control, it doesnt do automatically
2) if i have to use a physics engine, a tutorial, what shows how can i achieve it. every engine shows how boxes collide, how can i use clothes, how can i do fancy things, but none of them shows how can i achieve a simple collision, with no modify in rotation, no force application, etc
3) if irrlicht's collision system is enough, then what parameters should i give to it, if i want to use third person camera. so i need a model to collide, not the camera. i need to get the ellipsoid from bounding box of the model.
4) also i dont want it to slide down a hill below 45 degrees

about the project, its a tps, with jumps, walljumps, dodges, pushes, and things like that, so i want to control the gravity manually. or at least the engine should give me an interface to control it.

thanks in advice :3
Image
Image
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

If you're just looking for collision detection, Irrlicht should be fine. It slows down when you try and run collision detection on complex meshes, but this behavior is true of any engine you'll find. A common solution (used in professional games) is to use a second, invisible, low-detail mesh to run collision detection on that moves with the main mesh.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

well, ppl said in the forum, that we should use physics engine even for simple collision but..
if irrlicht collision enough, i still need answer for question number 3-4
Image
Image
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

any comments?

maybe i put this on the wrong forum? O.o
Image
Image
eye776
Posts: 94
Joined: Sun Dec 28, 2008 11:07 pm

Post by eye776 »

3) you could load it from an external file, rather than getting it from the bounding box (first find the ellipsoid that best fits your model)
4) you need to modify the collisionresponseanimator

As slavik262 said, you could (and should) use low-poly meshes attached to invisible scenenodes for collision detection.

You could also create your own simple TriangleSelector that inherits ITriangleSelector and returns transformed triangles for simple moving shapes (Box, Cylinder, Sphere for Doors, Traps, etc.) but I can't vouch that this would be the best method for doing moving obstacles.

If you want complex collision (eg: like in PoP games where bones collide with stairs and the like), you're better off using a proper physics engine.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

3) i think thats pretty lame sollution. we should be able to get it from bbox, so it'll be dinamical. let me tell you an example. i want changable clothes to my character. if i equip highwheels, my modell will be higher, but if i dont equip anything, it'll be lower. so i need dinamic method
4) i don't use collision response animator. just as i explained, i need to control the gravitation etc,

and so, im already using invisible low poly mesh for levels.

my current code:

Code: Select all

	pos = smgr->getSceneCollisionManager()->getCollisionResultPosition(
		mapControl.getTriangleSelector(), model->getPosition()-model->getTranslation(),
		model->getExtent(), nextStep - model->getPosition(), tri, hitpos, f, collisionOutNode, 0.0005f, vector3df(0,0,0));
	pos += model->getTranslation();

// and the gettranslation

vector3df PlayerModel::getTranslation()
{
	return vector3df(0,-getBoundingBox().getCenter().Y,0);
}
Image
Image
eye776
Posts: 94
Joined: Sun Dec 28, 2008 11:07 pm

Post by eye776 »

3) You can get it from the bbox, but please keep in mind that you need to account for the largest extent of your model's bbox (hint: it changes with animation).
You should probably look into making your own file format for storing extra info about the models used in your game at some point if you're serious about this.

Your code is quite trivial and doesn't really cover half of what you need (Sliding, stopping, not entering walls, unless you make constrained collision meshes).

I suggest making your own collision animator with a method such as "setGravity(f32 gravity)".
I also used to try and write around irrlicht but it's best if while using irrlicht you adapt to its paradigm of animators attached to nodes (it also makes your main logical code easier to maintain).
Not to mention you could also extend your animator (not irrlicht's) with
events / event handlers.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

3) no, i dont need it to extend. as i dont need very accurate collision, its enough for me, that i have the bounding box of the standing animation. i dont have problem with getting the radious of the ellipsoid, but rather i have problem with getting the translation. (what i use now makes my character slide down, if the map isnt straight)

.... of course its trivial. im asking here how to improve, how should i show u a code, what im asking how to do. lol

making a collision animator is a good idea. maybe ill try to improve the collisionresponseanimator, with functions what i need (teleport, get if its on floor, etc)

events? like onLand, onFall, etc? can u explain that little better please?
Image
Image
eye776
Posts: 94
Joined: Sun Dec 28, 2008 11:07 pm

Post by eye776 »

OK, sorry for the delay, but it was late last night so ...

You can get the "ellipsoid sliding algorithm" from ccollisionresponseanimator.cpp in the irrilcht sources.

As for wall running, falling, landing, use raycasts.

For example you use a 3d line from the player position downwards with a size of 1/5 of the player's height to preemptively dectect when a landing will occur.

the onLanding event should be launched ONLY when the character was in the air, had a gravitational acceleration a > 0 (a.k.a. was in the air), was about to land (see above) and last but not least, has landed.

you should also check for head collisions (same as before, with an upwards ray).

on falling is easy, as soon as the character has nothing beneath him(raycast), you trigger onFalling. The character object should also start with an onFalling() event (don't place it on the ground, but slightly above).
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

np, im glad u help

ok i understand what u are saying. i looked into the source of irrlicht collision response animator, and i think i can extend that with events, and things what u mentioned.
already put in the onLand event, apply some forces (differently calculed than the falling, but same technique), making pauses (like for walljumping, etc)
i think i can play around with this.

also found that i had some problems with bounding boxes etc, so now my collision are correct too :3

and also, found what slidingValue is. in the getCollisionResult function, it doesnt move the model, if the difference is smaller than the slidingValue. So, like when u standing on a not straight plane, its sliding down with a really slow speed. if you set up the slidingValue higher than that speed, it ignores that movement. i thought its better if the slidingValue is smaller, but setting it to 0.25 (it was 0.0005 before) solved my sliding problem :3
Image
Image
kamikaze942
Posts: 52
Joined: Wed Mar 03, 2010 7:11 pm

Post by kamikaze942 »

I've played around with Bullet, and implemented collision detection. I don't know if you want to go that route, but I was using the bounding boxes in irrlicht with some adjustments. When collision happened i used applied forces in bullet. Seemed to work well.
Kamikaze
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

my biggest problem is the player vs map. that cant be achieved by bounding boxes. How did u solve it?
Image
Image
kamikaze942
Posts: 52
Joined: Wed Mar 03, 2010 7:11 pm

Post by kamikaze942 »

so.... your biggest concern right now is the map collision i take it. I see you don't want to slide down a hill of 45 degrees. So what exactly do you want? Just walk down the hill normally? What kind of terrain are you using? In irrlicht i've used the collision response animator on a bumpmap terrain and I don't remember sliding down hills. In bullet there are forces such as friction, mass, etc.. So if I would increase the friction and weight the player wouldn't be sliding.
Kamikaze
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

yea, players vs mobs collision are made manually, so thats not problem.

and yeah, i dont want it slide (a human can stand on a plane, or cannot. but wont slide, unless he has skates XD).
And so, i tried bullet, and i didn't get how can i make my character dont bounce, dont rotate when colliding etc... but well, didnt try so much x3
But there wasn't an example how can i achieve this. Oh yeah there was a player vs BSP map as i recall, but my maps are simple models. so didnt found a good example for that, so i stopped trying xD
Image
Image
kamikaze942
Posts: 52
Joined: Wed Mar 03, 2010 7:11 pm

Post by kamikaze942 »

the forums from bullet are ok. I've prowled through there and found code for movements and rotations. there is no set position or set rotation function that ive found. I've been able to make my character jump, fly, and walk through it, not all of it perfected.

As far as the bouncing, i take it your going off a tutorial with the bouncing boxes and spheres perhaps? Try entering in an animated node, and then play with it. I believe i had to add alot of mass to my object, to get him to not bounce around. Play with friction properties for slides. off the createbox part of the tutorial, instead of bringing in acubescenenode, bring in your animated mesh.
Kamikaze
Post Reply