- Home /
Question by
unity_F07CCF81395FD875854B · Jan 27 at 05:09 PM ·
movementinputmouse
I can't move an object slowly after entering mouse inputs
I used a transform.position = Vector3.Lerp but after entering mouse input my object moves instantly. I need help,please.
if (inputmouse1)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
//Select stage
if (hit.transform.gameObject.tag == "Cube")
{
print("hit");
endMarker = marker1.transform;
if (startMarker != endMarker)
{
float distCovered = (Time.time - startTime) * speed;
float fractionOfJourney = distCovered / journeyLength;
//Set our position as a fraction of the distance between the markers.
transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fractionOfJourney);
endMarker = gameObject.transform;
}
}
}
}
Comment