- Home /
Shoot accuracy bar
What is the best way to implement a shoot accuracy system where in a horizontal bar a gun sight moves from end to end having the player to stop the gun sight in a certain area to hit the shot?
Should i use Lerp? The problem is that as time goes by i want the speed to increase
Please help me
Answer by DwaynePritchett · Aug 10, 2017 at 08:50 PM
I wouldn't say that this is the "Best Way", because that is subjective. But, Why can't you use that lerp function, but multiply the time value by a "speed" variable to increase the rate it moves left to right up to some cap speed? Ofcourse you will have to clamp it, but all the same, it should work. a lerp takes in 2 values(points), and a (t) time. Just spike the time by some amount. An example would be to have some variable, float Magnitude += (Factor)(Time.deltaTime); Lerp(A,B, t *magnitude). Then just clamp and adjust values. Hopefully this makes sense.
I tried to do it with a Lerp but when I go up the speed the gun sight makes a leap gigantic .. I think this happens since the lerp goes from 0 to 1 and when I raise the speed varies the position of the gun sight
I don't remember off the top of my head, but there is a variation of lerp that makes it go the opposite direction at the same speed. You want to go from, 0-1 and then 1-0. Worse case scenario you can keep track of the movement as "Positive/Right" or "Negative/Left", and then add 1-t, to invert the value when it's going left. $$anonymous$$ore plainly, make an if(goingRight){lerp like normal}else if(going left) {lerp(a,b,1-t). I think there is a lerp that goes both ways though, check the docs man. I think that is the problem anyways.
if I am missing the point of the "gigantic leap" as you called it. You might need to clamp your t value better, to smooth it out. Sounds like as the value gets larger it goes crazy.
Your answer
Follow this Question
Related Questions
UI object move? 2 Answers
clicking on button while moving on andriod 0 Answers
Question about an inventory system idea 2 Answers
How to resize an image by stretching only the center part 1 Answer