I have my player, When he lands on the rail I turn on isKinematic and lerp his transform.position to the next point. Now what I would like to do, Is make it so he moves towards the closest point in front of him or the direction he is going. I thought this would be easy, but im finding this extremely difficult.
This is what I've thought of so far :
1. create a raycast in front of the player
2. point the raycast to the closest point with tag "point"
3. move player towards raycast direction
This is what I have so far
if( OnRail == true ){
gameObject.GetComponent(Rigidbody).isKinematic = true;
transform.position = Vector3.MoveTowards(transform.position, nearRailPoint.transform.position,Time.deltaTime * force / 3);
}
I did try to come up with raycast code but nothings working. I am using javascript ( Yes i know, Im awful at learning code ), any help is appreciated thank you!
↧