Forum: General

Rotation toLocation

The JavaDoc is pretty unclear as to exactly what the toLocation method in Rotation is doing. This might be the method I need, but let me instead describe what I want and then hopefully someone can tell me the easiest way to do it.

Given the bot's current rotation, I want to get a Location that is exactly X distance units in front of the bot along its line of sight. I was hoping that there was a method that would turn the Rotation into a vector whose origin was the bot, and that pointed in the direction it was facing, since then I could simply scale and add this vector to the bot's Location.

Are there already some methods in place that will make this easy, or do I need to do some vector math to figure this out?
toLocation is the method you want to use. E.g.

Location OneHundredInFrontOfTheBot = info.getLocation().add(info.getRotation().toLocation().getNormalized().scale(100));


returns a location 100 ut units (~ 1 meter) in front of the bot. Just be careful - the vector will be in the same direction as the bot is currently looking to (so if the bot is looking up it will be above the ground). To account for this you can set the pitch attribute of the rotation you will be using to 0.
I think that toLocation converts Rotation to normalized location vector (but I've added getNormalized() just to be sure).
You might also check DistanceUtils static class - there are some useful methods (mainly for distance computations).
Thanks again. It looks like instead of setting pitch to 0, I can just use the getHorizontalRotation() method of the bot.