I succesfully implemented character movement in my proyect a few days ago, yesterday, I was trying to migrate the code to AngeScript, but it doesnt works. The character moves just in a slightly approximate direction to the click point and goes beyond it.
Here is my code:
navMesh = gameScene.GetComponent("NavigationMesh");
if (input.mouseButtonPress[MOUSEB_LEFT]){
IntVector2 pos = input.mousePosition;
Ray cameraRay = cam.gameCamera.GetScreenRay(pos.x / graphics.width, pos.y / graphics.height);
RayQueryResult result = gameScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, 300, DRAWABLE_GEOMETRY);
if (result.drawable !is null) {
Vector3 hitPos = result.position;
Vector3 pathPos = navMesh.FindNearestPoint(hitPos, Vector3(1.0f, 1.0f, 1.0f));
player.MoveTo(navMesh, pathPos);
}
}
Character update function:
[code] void Update(float timeStep)
{
if (currentPath.length > 0) {
animCtrl.PlayExclusive(“Models/Jack_Walk.ani”,0,true);
Vector3 nextWaypoint = currentPath[0]; // NB: currentPath[0] is the next waypoint in order
// Rotate Jack toward next waypoint to reach and move. Check for not overshooting the target
float move = 4.0f * timeStep;
float distance = (node.position - nextWaypoint).length;
if (move > distance)
move = distance;
node.LookAt(nextWaypoint, Vector3(0.0f, 1.0f, 0.0f));
node.Translate(Vector3(0.0f, 0.0f, 1.0f) * move);
// Remove waypoint if reached it
if ((node.position - nextWaypoint).length < 0.1)
currentPath.Erase(0);
}
}[/code]
The navigation mesh is generated in the editor. I ported to AS from my C++ code using AS skeletal sample as guide, but seems I missed something here.