Reputation: 631
I am developing a game and implemented pathfinding algorithm. My pathfinding returns me a array of nodes which character has to move through to reach the destination. Basically I need to tween node by node so I use TimelineLite and add all the tween to the sequence. It works.
HOWEVER,
There are delays when tweenning between nodes (character moves, then stop, then moves again...) which I couldn't figure out the reason. How can I solve it?
Here is the code:
public function walk(startNode:Node,destinationNode:Node):void{
//retrieve the path of the character
var path:Array = Pathfinder.findPath(startNode,destinationNode,GenericMap.findConnectedNodes);
currentPath=path;
if(path!=null){
var pastX:Number;
var pastY:Number;
for(var index:int=0;index<path.length;index++)
{
var currentNode:Node = path[index] as Node;
testMoveThroughNodes(currentNode.x,currentNode.y);
}
}
}
private var speed:Number = 0.7;
private var timeline:TimelineLite = new TimelineLite();
/** tween the sprite through nodes of path*/
private function testMoveThroughNodes(targetX:Number,targetY:Number):void{
timeline.append(new TweenLite(monster,speed,{x:targetX,y:targetY}));
}
I able to tween through each node sequencing TweenLite, however it moves and stop and moves, look totally unnatural.
Upvotes: 2
Views: 721
Reputation: 2970
Yeah, tough to say without seeing any code, but I wonder if it's just an easing issue that makes it LOOK like things are stopping briefly even though they're not. Remember, the default ease is Quad.easeOut, so movement slows towards the end of each tween (for a more natural "feel"). You can use Linear.easeNone if you want linear movement.
Upvotes: 3
Reputation: 684
Proberly keep updating his position when you create a new path so character.x and y update straight away, is this your problem or is it the animation itself if so creat a switch ex();
var switching = 0;
if(switching >0){
character.animationWalk.play();
}
if(switching <0){
character.animationWalk.stop();
}
Below is a file i made for fun but it has good time and animation control its in as2 but the concept is the same. Attached is source files.
http://ffiles.com/flash/games/sonic_hd_basic_sounds_animation_and_vector_3436.html
BJM Sydney
Upvotes: 0