Hi Unity community,
at the moment i’m building something that moves from one coordinate to another. My problem is only
that i want to give it a specific speed given by the user. For instance this code:
void Start()
{
private float timer = 0
}
void Update()
{
if(!positionreached)
{
timer += Time.DeltaTime;
float step = (userdefinedspeed/100) * 4 * Time.DeltaTime;
transform.position = Vector3.MoveTowards(transform.position, newPosition, step);
}
}
In the code the userdefinedspeed is a percentage of the maximum speed (4 m/s). From here it takes a strange turn. When using this code one would expect that the speed wil be 2m/s when having a percentage of 50% as the userdefined speed. When checking the timer values though a distance of 0.5m will not be covered in 0.25 seconds but most of the time it looks like it is a factor 10 off and it takes around 0.025 seconds. This corresponds with the visual effect of the gameobject as well. Does anyone know what i’m doing wrong?
greetings and thanks for the help
Hoogemast