Hello,
I’m working on a RTS and I have some trouble getting the object move smooth. It’s following the mouse correctly but very jumpy at some point.
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Physics.Raycast (ray, out hit, Mathf.Infinity);
if(hit.collider.gameObject.tag == "Ground"){
attachedObject.transform.position = new Vector3(hit.point.x,hit.point.y+3f,hit.point.z);
hittedGround = hit;
}else{
if(hit.collider.gameObject.tag == "layout" && transform.position!=hit.point){
attachedObject.transform.position = new Vector3(hit.point.x,hittedGround.point.y+3f,hit.point.z);
}
}
I’m using a Raycast to get the correct “y” of the terrain and saving that to be able when I hover over the object that I can still move it with the same “y”. But it seems between hitting the terrain and the object its a bit jumpy, like it gets moved to the position and after that moved to the correct “y”. It’s just an annoying effect. Maybe someone can help me.