[Pogamut-list] Movement Primitives and Steering

michal.bida pogamut-forum at diana.ms.mff.cuni.cz
Fri Jun 22 09:38:51 CEST 2012


Re: Movement Primitives and Steering

Author: michal.bida

You can easily do something like that using Pogamut Move command:

Simple example of code that first moves the bot right, then left, then backwards:
{CODE()}
int randomMoveDirection = 0;
	/**
	 * Last resort - keep trying random points 200 UT units from bot location - 90 degrees left, right and backwards. :-)
	 */
	protected void runSomewhere() {
		randomMoveDirection++;
		if (randomMoveDirection >= 2)
			randomMoveDirection = -1;
					
		Location backwardsLoc = bot.getLocation();
		
		Rotation rot = bot.getRotation();
		rot.setYaw(rot.getYaw() + randomMoveDirection * 16000);
		backwardsLoc = backwardsLoc.sub(rot.toLocation().getNormalized().scale(200));					
		
		double hDistance = bot.getLocation().getDistance2D(backwardsLoc);
		double vDistance = bot.getLocation().getDistanceZ(backwardsLoc);
		
		double angle = Math.atan(Math.abs(vDistance) / hDistance);		
		runner.runToLocation(initialLocation, backwardsLoc, null, focus == null ? backwardsLoc : focus, null, angle < MAX_ANGLE);
		
		bot.getAct().act(new Move().setFirstLocation(backwardsLoc).setFocusLocation(bot.getLocation().add(bot.getRotation().toLocation().getNormalized().scale(500))));
	}
{CODE}

It is good to have some basics from linear algebra - you'll be using things like this more than often. :-)

best,
m

-- 
Reply Link: <http://diana.ms.mff.cuni.cz/main/tiki-view_forum_thread.php?forumId=4&comments_reply_threadId=4&comments_parentId=965&post_reply=1#form>




More information about the Pogamut-list mailing list