working with Interpolate trying to find a constant speed

Player_EPlayer_E Member, PRO Posts: 604
edited November -1 in Working with GS (Mac)
I was messing with Interpolate earlier today and was wondering if there was a way to make a constant speed.

first let me go into more detail. I am using interpolate for movement. and interpolate is set up like this

interpolate self position X to move position X
Duration 2

(of course i have the Y counter part set up exact same)

In this example this is telling the actor to move from one point to another in 2 seconds. no matter how close or far the actor is from its destination it will take 2 seconds to get there. So if the actor is the full Distance along the X of 480 from its destination it will take 2 seconds to travel this. and if it is only has a distance of 5 along the X it will still take 2 seconds to travel. Which shows that the speed changes due to distance.

In math I found this very similar to the Speed formula
Speed=Distance/Time

Where Speed is the variable and the constants are Distance and Time. As defined by the interpolate rule set up Distance is difference from Self position X and move position X. and Time is the 2 seconds specified. and of course that is why you get the varied speed traveling different distances.

I have been trying to figure out if there was a formula to put in under the "Duration" section of interpolate that would give the results of a constant speed and a varied time depending on the distance.

so in theory formula would look like

Time = Distance/Speed

Although its not as simple as doing Distance/Speed because of the issue that would arise of the original X position being a greater number than the new position resulting in a negative number, but i assume that could easily be fixed by using absolute value.

Another issue that comes up is that the speed for traveling on the X axis and Y axis would not be at the same rate due to different numbers, so you could end up with an actor moving up faster than he does to the right which would make an L shaped pattern of movement.

Any thoughts on this idea to help build it would be very useful and im sure making a formula for this public would help out the community that way they would not have to use the "Move to" function.

Comments

  • ORBZORBZ Member Posts: 1,304
    View my project Shoot Where Touch XY. I show how to do what you are talking about.

    http://gamesalad.com/game/3097
  • Player_EPlayer_E Member, PRO Posts: 604
    Thanks Orbz ill check it out. Good to see you around here every now and then
  • MarkOnTheIronMarkOnTheIron Member Posts: 1,447
    Here's what I did on a project I'm working on (I can't download orbz project so maybe I used the same method as him):

    I have an actor that every X seconds moves to a random position. Normally I would have used a move to behavior but it doesn't work always and it's really buggy. The problem is that the actor should always move at the same speed.

    In the actor I created 3 attributes: NewX, NewY and interpolateTime.

    In the move rule I put a change attribute for NewX and NewY to random numbers.
    After 0.1 seconds I have a change attribute for interpolate time to max(0.1,(floor((magnitude(NewX-self.positionX,NewY-self.positionY))/50))/10)
    After 0.2 seconds use the interpolate to NewX and Y and in the time part use interpolateTime.

    This always give a number like 0.6 without other decimals. In the expression I used 50 because my actor should move at 500 speed but if you want slower speeds just change this number to whatever you like.

    It's working for me 100% of the time
  • Player_EPlayer_E Member, PRO Posts: 604
    I checked out your project orbz, its not quit what im looking for. Main problem im running into with your project is that it uses the move function and not interpolate.

    For the move function to work an actor has to be movable, but it does not have to be movable for interpolate to work. This is why I am trying to figure out something to use with interpolate.

    @mark I'll look into your method and see if I can tinker with that a bit.
  • Player_EPlayer_E Member, PRO Posts: 604
    @Mark

    A quick question about your method. From reading your post I get the idea that you only have 1 interpolate function for movement on both the X and y axis correct?
  • MarkOnTheIronMarkOnTheIron Member Posts: 1,447
    No, one interpolate for X and one for Y but the time is the same.

    Also if you want the actor rotation to match the direction it's facing add a change attribute for self.rotation to vectorToAngle(NewX-self.positionX,NewY,self.positionY).
  • Player_EPlayer_E Member, PRO Posts: 604
    ok i'll look into this some more tonight when I get out of class. Hope it works out
Sign In or Register to comment.