Actor sliding to mouse press issue

iAxilla

  • Posts: 17
Hello, I'm making a very big expert game and i ran into an issue. Well it's not actually an issue, i just don't know how to do this. So let's get to the thing.. I'm using Slide to for my actor, so when i click somewhere on screen the actor slides there. As you know you have to enter in how many seconds you want for actor to get to certain location but i want for my actor to have same speed when moving further away so seconds need to be dynamic somehow, how could i do this?

(Example: If i set seconds to 5 and click anywhere on screen actor will get there in 5 seconds which means that he will go faster if i click further away from him and i don't want that, I want the same speed.)

Please help.

sdieters

  • Posts: 2068
quite funny, i am working on a way to solve this when i saw this post haha.
you need to calculate the amount of seconds that it needs to slide to your new position. something like:

SlideSpeed = Distance between 2 points / amount of pixels you want to move per second.

speed = 100 pixels per second
distance of 25 pixels >> 25/100 = 0.25 seconds.
distance of 300 pixels >> 300/100 = 3 seconds.
distance of 500 pixels >> 500/100 = 5 seconds.
etc...

i havent tried this yet, but it was a theory that came in my mind today.
let me know if it works!
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

iAxilla

  • Posts: 17
I tried it like this and it still goes faster when i click further away:

((X of Self - X of Mouse Press) + (Y of Self - Y of Mouse Press)) / 100

Is this the right way of getting the distance between the two points?


sdieters

  • Posts: 2068
nope...
to get the distance between actors you need to work like this

sqrt((Xcenter of self- Xcenter of Mouse Press)^2 + (Ycenter of self- Ycenter of Mouse Press)^2)
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

iAxilla

  • Posts: 17
Okay now I did it the way you told me (see attached picture) but it still won't work as it's supposed to (still goes faster when mouse press further away). I have no idea what's wrong.

PhilIrby

  • Posts: 545
Not a slide to behavior, but I have a modification of the Follow the Mouse behavior called  Move to Mouse which uses a set speed.
The attr., Margin, simply gives the update event a better chance to catch the "Distance >  Margin"  condition.  With the speed set at 25, a Margin of 2 works well. At much higher speeds it might need to be increased a bit.

skippertech

  • Posts: 256
Hmm I tried the seconds adjusting idea you had, heres the math formula

Set Seconds to:  Square Root of ((Absolute Value of: (X of Actor - X of Mouse Press))^2 + (Absolute Value of: (Y of Actor - Y of Mouse Press))^2 )) then the whole thing is divided by 100..

The behaivor seemed to work, but it was so laggy and buggy it might as well have not. I clicked and a good 10 seconds after it moved, I tried bumping the denominator down to 20 (pixels per second) and didn't get any better.. any ideas? perhaps it just is too performance demanding