need little help with physics in racing game
need little help with physics in racing game
hello everyone i have nearly done with basic racing game i am using irrlicht and i love it i am using irrbullet (irrlicht implementation of bullet library) for physics the thing is i am using hidden walls on the road side so that my vehicle will not escape into outside world but when vehicle collide with these walls it randomly to other location just like in real collisions what i am looking for is when my vehicle collides with these walls it will stay stable but still can't penetrate through the walls and have smooth motion no jumping or rotation sorry for my poor english its not my native one hoping to get some feed back....
When it's all over, it's not who you were. It's whether you made a difference
Re: need little help with physics in racing game
Exclude the bounding wall mesh from bullet.
Do the wall avoidance steering behavior using irrlicht's collision detection by setting up selector for the wall.
When velocity vector of the node penetrates the wall, apply a repulsive force away from the wall.
Something like:
Regards,
smso
Do the wall avoidance steering behavior using irrlicht's collision detection by setting up selector for the wall.
When velocity vector of the node penetrates the wall, apply a repulsive force away from the wall.
Something like:
Code: Select all
core::vector3df getRepulsion()
{
// for simplicity, let speed = 1.0f;
core::vector3df dir = ... // heading of node:
dir.normalize();
core::line3d<f32> ray;
ray.start = node->getAbsolutePosition();
ray.end = (dir * COLLISION_DETECTION_RANGE) + ray.start;
scene::ISceneCollisionManager* cmgr = ...
core::vector3df intersection;
core::triangle3df hitTriangle;
const scene::ISceneNode* selectedSceneNode = 0;
bool ok = cmgr->getCollisionPoint
(
ray, selector, intersection, hitTriangle, selectedSceneNode
);
if (!ok) // nothing was hit
{
return core::vector3df(0.0f);
}
// calculate velocity component for collision avoidance:
core::vector3df normal = hitTriangle.getNormal();
normal.normalize();
f32 dsq = getWallPenetrationDepthSQ(intersection, ray.end, normal);
core::vector3df force = normal * REPULSION_CONST * sqrt(dsq);
return force;
}
f32 getWallPenetrationDepthSQ
(
const core::vector3df& intersection,
const core::vector3df& rayEnd,
const core::vector3df& normal
)
{
core::vector3df vect = rayEnd - intersection;
core::vector3df binormal = vect.crossProduct(normal);
binormal.normalize();
core::vector3df tangent = normal.crossProduct(binormal);
tangent.normalize();
f32 projectedLength = vect.dotProduct(tangent);
return vect.getLengthSQ() - projectedLength * projectedLength;
}
Regards,
smso
Re: need little help with physics in racing game
@smso seems a bit difficult for me but i will try to implement this thank you so much for your help
When it's all over, it's not who you were. It's whether you made a difference