#Clamping the Speed!
1 messages · Page 1 of 1 (latest)
what?
Clamp(Speed, min, max)
Now, the speed variable isn't detected.
And I've used a method to detect the speed:
`
public Vector3 prevPos;
prevPos = transform.position;
Speed = Vector3.Distance(transform.position, prevPos) / Time.deltaTime;
`
where do you create Speed
It's currently in the Update() function.
Show us
and where is the Vector3.Distance code
The prevPos is actually Vector3 not float! Sorry, mistaken...
Show us the important part of the script
The speed variable is also written but didn't give it any value because it wasn't calculated!
your not answering the questions
show the full code in a paste site #854851968446365696
Mathf.Clamp(Speed, ForwardSpeed, MaxForwardSpeed);
Alright.
just head to the clamp fution!
so you have a bunch of Mathf.Clamp doing nothing
because your doing nothing with the result
you want Speed = Mathf.Clamp(...);
yes
Alright, let me test.
but im pretty sure all the clamps wont work, only the last one since it runs last
What if I make 'em all in a single function and use && between them?
you probably want
if(reversing) //clamp reversed
if(going forward) //clamp forward
and anything else you need
Yeah, only the last one was working, Speed was clamped at 5!
I removed all of them except the second and it still worked, but to make the remaining ones work needs time!
when you do DriveForward() and the other ones, you can set either a bool to true or better make an enum for the states like forward, backwards, left, right whatever, and clamp based on the value of that enum
Alright, I'll postpone the subject for another time, it's 1:45 AM. Thanks for your help, time, patience and GoodNight!
Lol.