problems with collision [PLEASE HELP]

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.
Post Reply
Gogolian
Posts: 32
Joined: Sat May 17, 2008 10:49 pm

problems with collision [PLEASE HELP]

Post by Gogolian »

Hey,

I want my player to walk around on map with the same speed and possibly no glitches.
i have in my code:

Code: Select all

ISceneNodeAnimatorCollisionResponse* anim = smgr->createCollisionResponseAnimator(
			selector, node2, vector3df(5,50,5),
			vector3df(0,-500,0),
			vector3df(0,0,0));
everything seems to work fine except few things:

1. when player goes down from a "mountain" moving speed is increased (i think because of gravity)

2. when i set gravity to lower, the player starts to "float in the air" when going down from mountain (if i use isFalling() func. he will move down too slow)

3. when player is standing on side of a mountain, he is slipping down slowly. (I want to possibly get rid of it)

4. when player is leaved while he is slipping (about 30 seconds) sometimes he is sunking in terrain and only top of his head is visible

5. I want to know if i can do sth. about an angle of terrain, which player cannot pass. Tried to change vector3df(5,50,5) to vector3df(30,50,30), it done the thing but he is slowed down when climbing on terrain where the angle is that low that he can.

Link to code and compiled is here:
http://gogolian.lua.pl/WTF_collision.rar

Moving: WSAD or Pad (analog stick);)

[EDIT]
Oh, and one more thing, if this will be helpful:
There won't be any option to jump, i do not need it.
It is going to be like in Final Fantasy series.
And the darkness begun...
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I don't know if the irrlicht collision response animator will really cover what you need... you could improve it by writing your own version of the animator by copying the irrlicht version's code into a new class and making the necessary changes...

To stop him sliding down the hill you may be able to raise/lower (not sure which) the slidingValue, the last f32 parameter, and so that effectively gives him more friction against surfaces.

That may also help with your increased speed going down hill, but may make it slower to go uphill as well... It may also help with preventing him going up too steep a hill....

I don't know why he would sink into the terrain after a period of time being still... that's a bit strange...

So yeah, try and fiddle with the slidingValue and see if that helps, if not then you'll probably have to make your own version of the animator to account for your needs.
Image Image Image
robertgarand
Posts: 69
Joined: Fri Feb 22, 2008 6:47 pm
Location: montreal
Contact:

Own collision detection for relief following

Post by robertgarand »

Hi Gogolian,
I made my own collision detection routine for my objects to follow the terrain's relief. Works Ok with my terrain mesh. Adjust the down_vector to your need. Mine is "down_vector(0.0f,-30.0f,0.0f)" .
This way you have complete control over your object's behavior.
The idea is to throw a line down from object and adjust its Y position relative to the middle of the line. You could make object sink in or float above ground by changing values.

If you have any questions, be at ease, I can explain more.

Code: Select all

irr::core::vector3df movement,oldpos;
irr::f32 lapse = (now - last_time ) * data_level[current_level].tank_speedc;
			movement = direction * lapse;
			irr::core::line3df line;
			line.setLine(position, position + down_vector);
			if (bool we_collide = smgr->getSceneCollisionManager()->getCollisionPoint 
                   (line, selector, outCollisionPoint, outTriangle))
                    {milieu = line.getMiddle();
                    offset.Y = outCollisionPoint.Y- milieu.Y+3;
                    oldpos=position;
                    position.Y+=offset.Y;
                    position +=movement;
                    oldpos=position-oldpos;
                    }
			else 
                    {offset.Y= line.getMiddle().Y - outCollisionPoint.Y;
 //                   position.Y+=offset.Y+3;
                    position += movement;                 
                    }
                    outCollisionPoint=outTriangle.getNormal();
                    rotate =tank_mesh->getRotation();
                    rotate=oldpos.getHorizontalAngle();
                    rotate.Z=0;
                    if (rotate.X >360) rotate.X-=360;
                    tank_mesh->setRotation(rotate); 
                    tank_mesh->setPosition(position);
Hope it helps,
Robert
If it can't be writen, it can't exist
Gogolian
Posts: 32
Joined: Sat May 17, 2008 10:49 pm

Post by Gogolian »

ad JP:
Yeah, i forgot to mention that. I already tried to play with the "Sliding Value" but effects were not too good. (FE if i tried to wal up a hill when angle between character and hill was 90* was ok (he did'nt walk up) but if the angle was small ~45* he was walking up at normal moving speed ;)

ad robertgarand:
Thanks very much. Ill try this, if this is not what i want i think i aim to rewrite Irrlicht's collision manager like JP said.
Would you mind i use it in my game? ;) (your code?)
And the darkness begun...
robertgarand
Posts: 69
Joined: Fri Feb 22, 2008 6:47 pm
Location: montreal
Contact:

Ok to use

Post by robertgarand »

I'd be happy , feel free to use and modify, if you can improve it (shouldn't be hard) just let me know.
regards,
Robert
If it can't be writen, it can't exist
Gogolian
Posts: 32
Joined: Sat May 17, 2008 10:49 pm

Post by Gogolian »

well... did it... But i wouldn't call it improvement ;)
i just simplified it. For now it is:

Code: Select all

irr::core::line3df line;
line.setLine(node2->getPosition(), node2->getPosition()+vector3df(0,-100,0));
smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, outCollisionPoint, outTriangle);
node2->setPosition(vector3df(node2->getPosition().X,outCollisionPoint.Y+40,node2->getPosition().Z));
where node2 is my player node ;)
now I only require to declare: line, selector, outCollisionPoint, outTriangle.
it is very simple but work ;)
I wonder how can i set only Y of my player pos instead of declaring whole vector.
But whatever...
Anyway, thanks ;)
And the darkness begun...
Post Reply