(Sorry for my bad English i’m French)
Hello everybody, for the first time i’m posting here, i need your help :
I have a game who look like Click and Move, RTS, for now, i just have the character. Click Movement work, but when i place reflief on the terrain, the character start to move at Y=1 and go to Y=3 and fly between original position and the mountain. If it’s possible, how can i make my character go to Y=3 without flying ?
Doing Y=1 all time, and when encounter a mountain, up to this mountain ?
Same thing when the character start moving from y=3 to y=1.
Here is my code :
public class ClickMove : MonoBehaviour {
Ray ray;
RaycastHit hit;
public float speed;
Vector3 newpos;
void Start()
{
newpos = transform.position;
hit.point = transform.position;
}
void Update()
{
float step = speed * Time.deltaTime;
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetKeyDown(KeyCode.Mouse1))
{
if (Physics.Raycast(ray, out hit, 100))
{
newpos = new Vector3(hit.point.x, hit.point.y, hit.point.z);
newpos.y = newpos.y + 1f;
Debug.Log(hit.point);
}
}
Vector3 direction = newpos - transform.position;
Vector3 movement = direction.normalized * step;
if (movement.magnitude > direction.magnitude)
{
movement = direction;
}
GetComponent<CharacterController>().Move(movement);
// transform.position = Vector3.MoveTowards(transform.position, newpos, step); //LAST MOVEMENT BEFORE MODIFICATION
}
}
Here is a picture (With paint :D) In green what i want, in red what i have .
Thanks for your answers and again, sorry for my bad English.