So i wanna make like throwing a object that it moves from point a where he curenlty is to point b where the other player is and that only if range i tryed like this. the problem of my is that it goes to fast, and that its not if its only in range it can do it from everywhere
1. Calling Update inside start isn't necessary: Start will be called only once at startup. Update will be called each frame 2. Returning from start has no effect as update will be called nonetheless. 3. Lerps third value should be in range from 0 to 1. I would recording the current time on startup like this Code (csharp): var startTime : float function Start() { startTime = Time.time; } function Update() { transform.position = Vector3.Lerp(transform.position, end.position, (Time.time - startTime) / 5 ); } This will lerp over 5 seconds from 0 to 1
To make it go slower scale the time you pass into Lerp This example will go at half the speed. Code (csharp): // public script variables var speedScale = 0.5f; var timeSinceThrown = 0; //this is inside Update timesinceThrown += Time.deltaTime; transform.position = Vector3.Lerp(transform.position, end.position, timeSinceThrown * speedScale ); As for it doing it at any range, Update() gets called everyframe from the Unity engine if your script is a Unity MonoBehaviour. I'm assuming it is. What you'd be better off doing is checking the distance before the object is even created. Then this script only has to worry about movement and not the range. But if you want to do it this way then your Start function should set a boolean Thrown to true instead of calling Update() and then Update should check the boolean instead of its current condition.
Just to ask so i don't need to call any function before i write a code or do i always need to do a function