Game Development Community

Math help for Roomba

by Paul Jack · in Technical Issues · 01/06/2007 (6:48 pm) · 2 replies

I want to implement a Roomba that rides in a straight line around until it hits something, spins randomly, and then rides in a straight line.

Given Roomba's position and facing rotation, how can I compute the point that's X units from the position along the line? That's what I have to feed into setMoveDestination every tick.

Any help is greatly appreciated...

-Paul

#1
01/06/2007 (8:27 pm)
// Figured it out on my own

function newDestination(%roomba) {
// Vector to move forward 5 units
%vec = "0 5 0";

// Get roomba's current position/rotation
%pt = %roomba.getTransform();

// Multiply by delta vector
%delta = MatrixMulVector(%pt, %vec);

// Add delta to original position
%pp = %roomba.getPosition();
%newPos = VectorAdd(%pp, %delta);

// return result
return %newPos;
}

// Nothing to see here, move along...
#2
06/13/2007 (10:24 am)
Thank you for figuring this out. This is useful for my AI cover searching :-)