So I’m going for my first attempt at RayCasting with A*Pathfinding. Everything is going well I click and my path is set based on where the ray has hit, that’s all good. But my issue is setting the speed of my movement. Now I’m not using a character controller for various reasons.
Is there a simple way to slow the movement down? Here’s my code so far
using UnityEngine;
using System.Collections;
using Pathfinding;
public class PlayerPather : MonoBehaviour {
public GameObject theCamera;
public RayCast cC;
public Transform target;
Seeker seeker;
Path path;
int currentWaypoint;
float speed = 10;
float maxWaypointDistance = 1f;
// Use this for initialization
void Start () {
cC = theCamera.GetComponent<RayCast>();
seeker = GetComponent<Seeker>();
seeker.StartPath(transform.position, cC.targetposition, OnPathComplete);
}
public void OnPathComplete(Path p){
if(!p.error)
{
path = p;
currentWaypoint = 0;
cC.gothere = false;
}
else {
Debug.Log (p.error);
}
}
void FixedUpdate(){
if(cC.gothere == true){
seeker.StartPath(transform.position, cC.targetposition, OnPathComplete);
}
if(path == null){
return;
}
if(currentWaypoint >= path.vectorPath.Count){
return;
}
transform.position = path.vectorPath[currentWaypoint];
if(Vector3.Distance (transform.position, path.vectorPath[currentWaypoint]) < maxWaypointDistance){
currentWaypoint++;
}
}
}
You are not using any speed at all, as far as I can see.
I expect that your character moves really fast to the target because you just put him on every waypoint.