Hi imranhabib,

Naturally the task is not directly handled by Horde3D, which is purely a rendering engine and does not handle physics-based calculations for you. It does, however, provide raycasting functionality which you can use for determining the distance of your character from a given wall (from your post, I assume you already have the collision distance worked out). I gave a basic approach to solving this in

another topic which you've also commented on, so you use that for manually working out distances too. With that in mind, you can progress in one of two main ways; incorporate a self-contained physics engine (such as Bullet, PhysX, Havok Physics, etc.), or write your own collision response.

Integrating an existing physics engine will give you far greater functionality when dealing with physics meshes, character controllers, collision detection and response, as well as access to more advanced features (ragdolls, hinges/joints...) for later development. Depending on your requirements, this would be a comprehensive solution to almost any physics-related problems you come across. If you want something more lightweight, however, you may want to consider writing your own collision handler.

As I understand it, you have a method of finding the distance the agent has from a given wall - if your requirement is simply to not go through the wall (no bouncing off or sliding involved) then this should be no problem to implement manually. Put simply, you need to know whether the agent is being moved towards the wall or away from it; finding the wall's surface normal should suffice. Once you know the direction the wall is facing in, you can compare it to the direction the agent is moving in (not necessarily the direction it is facing, if it can move sideways or backwards for example). As long as the agent is moving in the same general direction as the wall's surface normal, up to +/-90 degrees either way, it should be allowed to move. The quickest way to work out if the two vectors are facing in the same general direction is by finding the dot product of them:

**Code:**

Vector3 wallNormal(1, 0, 1); //the direction your wall is facing in (currently 45 degrees)

Vector3 moveDirection(0, 0, 1); //the agent's movement direction (in this case, directly forward in the z-axis)

float product = GameMath::dotProduct(wallNormal, moveDirection); //find the dot product

Naturally, the code will vary depending on your implementation. At the very least, you need to calculate the dot product in the following manner:

**Code:**

static float dotProduct(const Vector3 &lhs, const Vector3 &rhs) const

{ //Vectors should be of unit length before this is calculated

return (lhs.x * rhs.x) + (lhs.y * rhs.y) + (lhs.z * rhs.z);

}

The dot product is commutative, so it doesn't matter which way around the values go. If the result is a negative number then it means the agent is moving into the wall; if he is within the wall's collision distance and the calculated product is negative, then it is colliding. If the result is positive then the agent is moving away from the wall (i.e. in the same general direction as the wall). Therefore, in the example above, the moveDirection is away from the wall and should therefore be allowed (unless it collides with a different wall).

This solution should get you a method which stops your agent moving into the wall, but it will 'stick' to the surface until it tries to move away. There are several ways of refining this, depending on your application's requirements. Sliding along the surface of the wall should be quite straightforward with some number crunching; work out how much lateral movement is left if you subtract the wall's surface normal from the agent's movement, and apply that movement to the agent instead. Other less elegant methods include allowing the agent to move into the wall, calculating how far it has pushed in, and directly relocating it outside of the wall; usually effective, but can lead to

tunnelling. There are many more hidden issues whenever physics is introduced, especially when dealing with many objects bunched together.

Hope this helps!

Thank you So much.

I have carefully read it, but for now i am using another techinque using recasting a ray from keyboard controlled function and hopefully i can use your suggested points also, and if i came up with something i will surely share it