So here is my formula to first calculate the distance from the original position of the sprite from the position it is told to go to (mouse click). I then put it into a code that basically takes that distance and divides it by 62.5 (that is the speed I want my sprite to move at , 62.5 units/second). Can someone help me figure out what is wrong and why at some positions it goes much much to slow or waaaay to fast and sometimes works perfectly.
when I receive [Move v] set [DistanceVariable v] to ( [abs v] of ( [sqrt v] of ((((MouseX) - ( [x position v] of [Sprite3 v] )) * ((MouseX) - ( [x position v] of [Sprite3 v] ))) + (((MouseY) - ( [y position v] of [Sprite3 v] )) * ((MouseY) - ( [y position v] of [Sprite3 v] ))))))
Offline
troyk wrote:
So here is my formula to first calculate the distance from the original position of the sprite from the position it is told to go to (mouse click). I then put it into a code that basically takes that distance and divides it by 62.5 (that is the speed I want my sprite to move at , 62.5 units/second). Can someone help me figure out what is wrong and why at some positions it goes much much to slow or waaaay to fast and sometimes works perfectly.
when I receive [Move v] set [DistanceVariable v] to ( [abs v] of ( [sqrt v] of ((((MouseX) - ( [x position v] of [Sprite3 v] )) * ((MouseX) - ( [x position v] of [Sprite3 v] ))) + (((MouseY) - ( [y position v] of [Sprite3 v] )) * ((MouseY) - ( [y position v] of [Sprite3 v] ))))))
First of all, you don't need the absolute block as the sqrt function will always give you a positive answer. Secondly, could I see your movement script? The problem might be in there.
With regards,
ErnieParke
Last edited by ErnieParke (2013-03-23 11:49:53)
Offline
ErnieParke wrote:
First of all, you don't need the abstract block as the sqrt function will always give you a positive answer. Secondly, could I see your movement script? The problem might be in there.
With regards,
ErnieParke
Abstract block? The abs?
That means absolute value...
Offline
kayybee wrote:
ErnieParke wrote:
First of all, you don't need the abstract block as the sqrt function will always give you a positive answer. Secondly, could I see your movement script? The problem might be in there.
With regards,
ErnieParkeAbstract block? The abs?
That means absolute value...
Oh... Yes, you're correct; my mistake. Well thanks for catching it!
With regards,
ErnieParke
Offline
what if when you are trying to find the distance between 2 mouse clicks?
Offline
dinosaur1995 wrote:
what if when you are trying to find the distance between 2 mouse clicks?
Well for that, all you need to do is store your previous mouse click in two variables, (P Mouse Click X) and (P Mouse Click Y), and whenever you click, you can then use the distance formula, though make sure that you record the mouse's click position only after that has occurred or else you'll keep on getting a distance of 0.
So, for example:
if (mouse down?) set [distance v] to ([sqrt v] of ((((P Mouse Click X) - (Mouse X)) * ((P Mouse Click X) - (Mouse X))) * (((P Mouse Click Y) - (Mouse Y)) * ((P Mouse Click Y) - (Mouse Y))))) set [P Mouse Click X v] to (Mouse X) set [P Mouse Click Y v] to (Mouse Y) wait until <not (mouse down?)> end
Last edited by ErnieParke (2013-04-18 06:38:30)
Offline