Help with Moving an animated player with Interpolation
Member RThurman had this post a while back showing how to create your own interpolations, and thus create interpolations that don’t override/interfere with collisions.Here’s a link…
http://forums.gamesalad.com/discussion/54962/make-your-own-interpolations/p1
I am trying to adapt the linear interpolation example he gave in his templet to an animated character moving along the X axis .
Right now, the way I have it set up…
A mouse button down on either side of my character’s self positionX triggers the interpolation to that x position, sets up a game direction and starts the appropriate animation.
Problem is a new mouse button down on the opposite side of self position X while the interpolation is running, causes the animation to face the direction of the new mouse button down while the interpolation continues moving in the opposite direction to it’s end position. (Moon Walk)
I would like the new mouse button down to stop the first interpolation and start a new interpolation to the new x position.
——————OR————
I would like a new mouse button down while the interpolation is going to have no effect on the animation.
Heres a look at what I have……
——————————————————————————————————
——————————————————————————————————
——————————————————————————————————
In the game attributes I have one text attribute :
direction text
In the Character attributes i have the following:
myBeginTime 0 real
myBeginningX 0 real
myEndingX 0 real
myDuration 0 real
halfWay 0 real
myBeginningY 0 real
myEndingY 0 real
distanceFromGoal 0 real
Interpolate??? boolean
In the Character the rules are setup as follows:
————————————————————————————————
Rule: trigger interpolation to mouse position right
when all conditions are valid:
actor receives event_ mouse button is down
attribute game .mouse.positionX_greater than or equal_self .positionX
change attribute_self.Interpolate??? _to true
change attribute_game.direction_right
————————————————————————————————
Rule: trigger interpolation to mouse position left
when all conditions are valid:
actor receives event_ mouse button is down
attribute game.mouse. positionX_less than or equal_self.positionX
change attribute_self.Interpolate??? _to true
change attribute_game.direction
——————————————————————————————
Rule: lets interpolate
when all conditions are valid:
attribute_self.interpolation???_is true
group: Set up interpolation parameters
change attribute_self.myDuration_to _2
change attribute_self.myBeginningX_to_self.positionX
change attribute_self.myEndingX_to_game.mouse..positionX
change attribute_self.myBeginTime_to_self.time
timer:do the interpolation during the allotted time
for_self.myDuration_Run to completion-checked
change attribute_self.positionX_to_(( self.Time - self.myBeginTime )/ self.myDuration )*( self.myEndingX - self.myBeginningX )+ self.myBeginningX
timer: set interpolate back to false
after_self.myDuration_Run to completion-checked
change attribute_ self.myDuration_to_false
——————————————————————————————
Rule:Idle animation
When all conditions are valid:
attribute_self.interpolation_is false
attribute_game.mouse.positionX _is greater than or equal_self.positionX
animate(idle animation facing right)
otherwise
animate(idle animation facing left)
——————————————————————————————
Rule: animate right
when conditions are valid:
attribute _self.interpolation???_is true
attribute_game.direction_is right
animate(running right anima)
——————————————————————————————
Rule: animate left
when conditions are valid:
attribute _self.interpolation???_is true
attribute_game.direction_is left
animate(running right anima)
Comments
Hmmm.... I think you mostly have it working. Although it seems like a linear interpolate could be accomplished with a 'moveto' behavior without the need for a custom interpolate.
Is it just that the animation left/right is triggering when it should not? If that is the case, then its a logic error. Make the changes in bold and it should keep the animation from flipping prematurely.
In the game attributes I have one text attribute :
direction text
In the Character attributes i have the following:
myBeginTime 0 real
myBeginningX 0 real
myEndingX 0 real
myDuration 0 real
halfWay 0 real
myBeginningY 0 real
myEndingY 0 real
distanceFromGoal 0 real
Interpolate??? boolean
In the Character the rules are setup as follows:
————————————————————————————————
Rule: trigger interpolation to mouse position right
when all conditions are valid:
actor receives event_ mouse button is down
attribute game .mouse.positionX_greater than or equal_self .positionX
attribute_self.Interpolate??? is false
--change attribute_self.Interpolate??? _to true
--change attribute_game.direction_right
————————————————————————————————
Rule: trigger interpolation to mouse position left
when all conditions are valid:
actor receives event_ mouse button is down
attribute game.mouse. positionX_less than or equal_self.positionX
attribute_self.Interpolate??? is false
--change attribute_self.Interpolate??? _to true
--change attribute_game.direction_left
——————————————————————————————
Rule: lets interpolate
when all conditions are valid:
attribute_self.interpolation???_is true
group: Set up interpolation parameters
--change attribute_self.myDuration_to _2
--change attribute_self.myBeginningX_to_self.positionX
--change attribute_self.myEndingX_to_game.mouse..positionX
--change attribute_self.myBeginTime_to_self.time
--timer:do the interpolation during the allotted time
--for_self.myDuration_Run to completion-checked
----change attribute_self.positionX_to_(( self.Time - self.myBeginTime )/ self.myDuration )*( self.myEndingX - self.myBeginningX )+ self.myBeginningX
--timer: set interpolate back to false
--after_self.myDuration_Run to completion-checked
----change attribute_ self.myDuration_to_false
----change attribute_ self.Interpolate???_to_false
——————————————————————————————
Rule:Idle animation
When all conditions are valid:
attribute_self.interpolation_is false
attribute_game.mouse.positionX _is greater than or equal_self.positionX
--animate(idle animation facing right)
otherwise
--animate(idle animation facing left)
——————————————————————————————
Rule: animate right
when conditions are valid:
attribute _self.interpolation???_is true
attribute_game.direction_is right
--animate(running right anima)
——————————————————————————————
Rule: animate left
when conditions are valid:
attribute _self.interpolation???_is true
attribute_game.direction_is left
--animate(running right anima)
Thanks man, I was setting this up with my kids and I was stuck for hours trying to figure it out.
Hey I've been thinking about this for a few minutes. (Translation: Its snowed three inches and I've been out shoveling the drive. So I've had plenty of time to think about things.)
It seems to me that using a moveto behavior will accomplish a liner interpolation just fine. Since speed is distance/time, it will be much easier to do the movements you want with a moveto behavior (that manipulates speed).
Attached is an example that mimics interpolation by using a moveto behavior. It adjusts the the speed so that it always takes 5 seconds to finish the movement. To me, this approach seems much easier to implement and will be easier to maintain than the 'roll your own interpolation' idea.
Special thanks to @jamie_c who supplied some free game graphics:
http://www.jamie-cross.net/?p=450