This is final version of my code but still it is not working like i wanted it. When ı click it goes like teleporting or fast movement. When ı click to a position which ı wanted to go, ı want do that slowly without constantly. how can ı apply what you have said to my code ? Thanks
public float speed = 15.0f;
// Start is called before the first frame update
Vector3 newPosition;
void Start () {
}
void Update()
{
float step = speed * Time.deltaTime;
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
newPosition = hit.point;
transform.position = Vector3.MoveTowards(transform.position, newPosition, step);
}
}
Move line 21 downward outside the if ( ) block, so it runs every Update.
Edit: I would suggest when you’re testing things, start out with rather slow values for speed. Right now you have speed = 15f which (depending on the scale of your world) would represent 15 meters per second, which is faster than Usain Bolt sprinting.
What i am making is a spiderman swinging game. I want a feature like between 31 and 33 seconds of this video(another example 1:10 1:11). Going to mouse click position with time and without lagging or teleporting. Constant movement. What ı have to change for that ? Thanks for help
Looking at this game there looks like there’s many different movement modes they’re switching between over time. It’s either freefall, wallrun, web sling, web pull, and probably a bunch of other subtle variations of the above. ALL of them just change the velocities applied to the player, and of course trigger appropriate animations.