local x = t.x
local y = t.y
local dis = calcDistance(x,y,self.ball.x, self.ball.y)
while dis > self.range do
if x > self.ball.x then x = x * .9999
else x = x * 1.0001 end
if y > self.ball.y then y = y * .9999
else y = y * 1.0001 end
dis = calcDistance(x,y,self.ball.x,self.ball.y)
end
So I have a character and he is surrounded by a force field type thing. If you click inside the force field, the character moves to the point that you tapped. If you tap outside, I want it to round it so that the position you clicked is proportional to a valid position.
Example: the ball is at 100, the range is 150. If you click the position vec2(0,400) it would scale the y down and the x down as until the values are within range…
calcDistance does what you’d assume it to do.
However I have 2 issues and 1 and maybe 1 “how would I completely redo this section of code”
So let’s go…
- When t.x or t.y are negative, program is caught in an infinite while (-1 * 1.001 just takes you further away from the intended value)
- When the screen cords become major…something like (10000000,1000000)… 1.0001 * whatever will give you a value far outside the range of the player. This is because the range is a constant but the position is not so my question: how do you scale it properly?
- How would I completely redo this? This question assumes this is an issue that someone else has faced before (maybe with their virtual joystick constrictions)…thoughts?
Anyway guys. I’m eager to hear your feedback and suggestions