Hi, Im creating paths that the NPCs will follow at certain moments, but I need to make them collide with the player, the player is a CC, so it just collides if the player walks over the NPC, not if the NPC walks over the player…
So my first try was to make the NPC a CC and move it with CC.Move, using the iTween.PointOnPath() as the destination…I dont have a clue of whats happening since doing this makes the NPC explodes to somewhere in the universe…The same code actually works if instead of using CC.Move( dest ) i use transform.position = dest.
So, maybe thats isnt even the best solution…How can I make things that arent RB collide with the player and other things? If I was right and the best is to use CCs, than why my code doesnt work with CCs?
Heres my current test code:
public class moveCCPath : MonoBehaviour
{
float valueOnPath = 0.0f;
CharacterController CC;
public int estado = 0;
// Use this for initialization
void Start()
{
CC = gameObject.GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
if (estado == 0)
{
estado = 1;
iTween.ValueTo(gameObject, iTween.Hash("from", 0, "to", 1.0f,
"time", 6,
"easetype", iTween.EaseType.linear,
"onupdate", "myOnUpdate", "onupdateparams", "currentpercent_p",
"oncomplete", "myOnComplete"));
}
if (estado == 2)
{
estado = 3;
iTween.ValueTo(gameObject, iTween.Hash("from", 0, "to", 1.0f,
"time", 6,
"easetype", iTween.EaseType.linear,
"onupdate", "myOnUpdate", "onupdateparams", "currentpercent_p",
"oncomplete", "myOnComplete"));
}
}
void myOnUpdate(float currentpercent_p)
{
Vector3 newPos = transform.position;
if (estado == 1)
{
//pega o ponto no caminho de acordo com a animacao da porcentagem
newPos = iTween.PointOnPath(iTweenPath.GetPath("clienteGo2"), currentpercent_p);
}
else if ( estado == 3 )
{
//pega o ponto no caminho de acordo com a animacao da porcentagem
newPos = iTween.PointOnPath(iTweenPath.GetPath("clienteBack2"), currentpercent_p);
}
CC.Move(newPos);//PROBLEM
//transform.position = newPos;//WORKS
//look to a point ahead in the path.
//transform.LookAt(iTween.PointOnPath(iTweenPath.GetPath("clienteVolta"), (currentpercent_p+0.2f)));
}
void myOnComplete()
{
if (estado == 1)
estado = 2;
else if (estado == 3)
estado = 0;
}
}