interpolate drama.. moving an object around on screen by click destination

part12studiospart12studios Member Posts: 620
edited October 2012 in Working with GS (Mac)
Hi there,

I've been working on a game where i am allowing a vehicle to be positioned from where it is to another location within a radius of the current position.

The core problem i'm having is that it works.. but the weird thing is that when i click the destination the first time it works.. then the 2nd time i do it it doesn't.. but then the 3rd time i do it it does it!

to offer some contrast, doing a direct "change attribute" works perfect each time..

what it feels like is that the interpolate transition needs to reset somehow and i've tried a number of different approaches to this but nothing is working. nothing is working through..

Is there some other better way to move an object around? I've tried things like "move too".. using the x and y of the two interpolates i'm using to create a nice tween like effect..

its just so bizarre how its behaving.. its all working as i like EXCEPT this thing about having to click the action twice each time.. i'm confident as best i can tell that various conditions are resetting correctly.. this is backed up by the fact that "change attribute" replacements work perfect each time.. but that result is unacceptable because the actor jumps to the new location instantly.

Oh yea one other thing.. the interpolate issue doesn't happen IF i don't let the actor come to a complete stop. strange stuff.. if i keep the interpolate in motion.. then it works.


Thanks
Caleb

Best Answers

Answers

  • part12studiospart12studios Member Posts: 620
    @tatiang thanks for taking a look at this!

    Ok let me see if i can break it down clearly.. there is probably a more elegant way to do what i'm wanting too..

    https://www.dropbox.com/s/tq1go32byn4akkh/example.png

    ok so to explain what i'm trying to do.. the idea is that touching the vehicle actor (the one i want to move).. a radius graphic appears.. the rules above are from within that radius graphic.

    Actor receives touch and "game.movement armed" true.. (made true by touching the vehicle in the first place). This stuff is happening inside the radius graphic, which is what keeps the player from only being able to move so far away from where the vehicle currently is.

    change attribute - the x position of the "stop here" actor

    change attribute - the y position of the "stop here" actor

    NOTE: This invisible actor was my way of insuring that the x/y of the mouse stayed put.. i tried just having the tanker move to where i clicked, but the interpolate when listening directly to "mouse postiion x/y" it would track the mouse till the interpolate timer stopped. Again probably a more elegant way to achieve this, but this was the best i could come up with..

    Interpolate TankerX to move to X

    Interpolate TankerY to move to Y

    NOTE: this is the crux of the problem. If i replaced these values with a change attribute it works solid every time, but the problem is that i need the actor to move from point a to point b.. not jump instantly.

    Change Attribute - Game Movement False.

    Change Attribute - Game movement Modulo to 0

    NOTE: these attributes do things like False (makes radius go invisible and prevents incidental touches in the radius area from occurring) and modulo of course insures that the on action touching the vehicle allows it to cycle on/off well.



    Thanks!
    Caleb
  • part12studiospart12studios Member Posts: 620
    @RThurman hey that's great to know how to make interpolates. perhaps if i simply change the values from here (using change attribute, which i was saying before works fine.. then you're suggesting i put these constraints on the vehicle itself when it receives the value changes?
  • part12studiospart12studios Member Posts: 620
    I did find a solution to the problem although i didn't use these specific techniques mentioned. it turns out that putting the interpolate in the "move to here" actor did the trick. however to prevent some of the weirdness if i clicked too fast was to put a cooldown preventing the vehicle to perform another move till the interpolate completed itself.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited October 2012
    @part12studios -- Glad you got it working!

    Interpolation is just a way to plot points between two known points. (Just like extrapolation is a way to plot points beyond two known points.)

    Perhaps an explanation of one of the equations will help others who read this to see how linear interpolation can work:

    Constrain Attribute: self.Position.X To:self.Position.X+((game.Mouse.Position.X - self.Position.X)*.25)

    The above constrain is is telling the actor to move its x position one fourth (25%) of the distance between its current position and the mouse. Because its a constrain, it does this on every frame update. It is interpolating one point on every update. However, because its one fourth closer on every update, its distance between itself and the mouse decreases every frame. So the closer it gets to the mouse, the less distance it needs to travel. In effect, it looks like its slowing down as it gets closer to the mouse. (Because it actually is!)
  • part12studiospart12studios Member Posts: 620
    @RThurman thanks for the explanation! I really wish that GS would devote some section of the cookbook to stuff like this.. while you don't have to be a programmer to make a game, understanding how to use the various functions is not something that is nearly as intuitive as most Behaviors are or as easy to experiment with..

    for one thing.. the formula entry space really should be a dynamic field that adjusts to the text field size or simple stretches to fit whatever size the box that contains it so you don't have to mouse over each equation.. one is fine.. but Rules can often have numerous ones side by side making it very tedious to compare..
  • part12studiospart12studios Member Posts: 620
    that would be awesome. i do see how it could get tricky. my solution was maybe not the best way.. but it got the job done. i created a "place holder" actor that would be spawned when clicked.

    So yea even though i found a solution and it works for the purpose i need (doing a cooldown to restrict moves), it still felt like there is probably a better / smarter way to dynamically do this without having to use smoke an mirrors (cooldown) to get the desired effect.

    Thanks!
    Caleb
  • GLGAMESGLGAMES SingaporeMember Posts: 988
    the place holder actor is useful actually if you like to have waypoints plotted out even when the first movement have not been completed. Maybe store the way points in a table as you tap on the screen. and everytime the actor moved to the waypoint it will check if there's a 2nd set of coord from the table and move to it else stop. Of course you may nd to limit the no. of waypoints allowed and also clear the table once all movement is completed.
  • part12studiospart12studios Member Posts: 620
    @tenrdrmer hey thats very cool. I'm going to analyse these today for sure! Thanks for sharing. It seems like topics like this (with awesome examples like this) should have some place in the cookbook so folks can study situations like this if they do a search for "interpolate".. maybe break up examples like this by behavior where folks can link/upload template examples like this.
Sign In or Register to comment.