Page 1 of 1

How to turn and face direction to next waypoint

Posted: Wed Feb 06, 2013 10:41 pm
by Rickster
Hi there,

how can i get my char to turn direction to the naxt WP?

When reaching one waypoint, I want to change char direction and camera view to the next waypoint, without movint to the next WP.

Thanx
Ric

Re: How to turn and face direction to next waypoint

Posted: Thu Feb 07, 2013 1:10 am
by rock5

Code: Select all

player:aimAt(__WPL:getNextWaypoint())
I think that should work.

Re: How to turn and face direction to next waypoint

Posted: Thu Feb 07, 2013 1:14 am
by Mer-Ki-Vah
Call this function:

Code: Select all

function lookatTarget(X,Z,Y)   
   local angle  = math.atan2(Z - player.Z, X - player.X);
   local yangle = math.atan2(Y - player.Y, ((X - player.X)^2 + (Z - player.Z)^2)^.5 );                  
   player:faceDirection(angle, yangle);
   camera:setRotation(angle);
end

Re: How to turn and face direction to next waypoint

Posted: Thu Feb 07, 2013 1:32 am
by rock5
Ah yes, my command only turns the camera

Re: How to turn and face direction to next waypoint

Posted: Thu Feb 07, 2013 5:22 am
by Rickster
thanx!

i call the function this way

Code: Select all

lookatTarget(__WPL:getNextWaypoint().X,__WPL:getNextWaypoint().Z,__WPL:getNextWaypoint().Y)
and it works fine :)

btw, how can i get accass to the actual WP info? i could not find this info in the wiki - Waypoint File Functions

i would like to get the actual WP index. i am using this as a workaround

Code: Select all

wp_index = __WPL:getNextWaypoint().wpnum - 1 
:D but i would also like to get access to the rest of the actual wp´s table.

Re: How to turn and face direction to next waypoint

Posted: Thu Feb 07, 2013 5:42 am
by lisa
you mean this?

Code: Select all

__WPL.CurrentWaypoint
basically use __WPL instead of self for this stuff

Code: Select all

		self.Waypoints = {};
		self.CurrentWaypoint = 1;
		self.LastWaypoint = 1;
		self.Direction = WPT_FORWARD;
		self.OrigX = player.X;
		self.OrigZ = player.Z;
		self.Radius = 500;
		self.FileName = nil;
		self.Mode = "waypoints";
		self.KillZone = {};
		self.ExcludeZones = {}

Re: How to turn and face direction to next waypoint

Posted: Thu Feb 07, 2013 5:49 am
by rock5
All the waypoints are stored in a table in __WPL.Waypoints. __WPL:getNextWaypoint() returns the 'currentwaypoint' which is one of those waypoints. When moving between waypoints the 'currentwaypoint' is the one you are heading towards. When you reach a waypoint and it is executing the code there, the 'currentwaypoint' is the next waypoint. If you want information about the waypoint you are at you can get it like this

Code: Select all

thiswp = __WPL:getNextWaypoint(-1)
thiswp will include X, Z, Y, Action, Type, Tag and wpnum (wpnum is not normally part of the __WPL table but is added in that function). You can also get the wp number you are at with __WPL.CurrentWaypoint-1.

Hope that wasn't too confusing.

Re: How to turn and face direction to next waypoint

Posted: Thu Feb 07, 2013 6:54 am
by Rickster
nope, not confusing. that was exactly what i needed! :) thank you all!