Jump to content

Moving along the path


Rick
 Share

Recommended Posts

So I have the pathfinding setup for a thingoid. I need to go over my list and move my character along it. The list is x,y values of the 2D array that is the grid. One approach I have done before was to interpolate a bunch of actual location points between each node, and then move my model to each of these points over time. The points are close enough that this looks smooth.

 

Another way I've done it is to just get the center points of these nodes and point the model to the next node in the list and move the controller and then check if I'm at or close to the center of the current node, then get the next node. I want to like this method but I've used EntityDistance() to determine if the model was at or close to the center point of the current node and this has caused issues sometimes. Sometimes if something external causes my app to slow down the character controller will fly right by. There just seems like using EntityDistance() with the character controller and a point can be delicate.

 

 

So what other methods have worked for people to move a character controller along a path of "nodes".

Link to comment
Share on other sites

Say you have 30m between nodes... and for example sake your controller moves 7 m per frame because your computer is going slow so we get some psuedo code like this:

 

1. Get distance between player and next node

2. If 'distance' >= 7m, move player 7m towards node goto step 5.

3. else 'remainder' = 7-'distance'. Move controller forward by 'distance' (eg.28m in and only 2m to go to 30m so move forward 2... remainder = 7-2=5)

4. Point controller to the next node in the list and Move controller forward by 'remainder' (eg. move controller 5m towards the next node)

5. end

 

 

That should do the trick.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Is there a way to calculate how much the controller actually moves in a given frame? I know for example sake you say 7m but that would be a variable speed given speed of the app right?

 

Move controller forward by 'distance'

 

How would I do that? Would I have to calculate the move variable that passes to the controller and if so what is that calc? Using any sort of MoveEntity or PositionEntity would stop the physics on it. Maybe we don't care for such a small amount but could that cause issues somehow?

 

I really wish LE had a MoveTo type of method :)

Link to comment
Share on other sites

:)

 

My NPC have controller,head pivot and mesh

 

Each UpdatePhysics i have one current NPC target, and i do this:

 

1. set head pivot to controller position

2. point head smooth to current target waypoint

3. move controller forward using head.Y as controller turn

 

Something like that. Movement is smooth enough.

 

On NPC creation

function create_bot(obj)

obj.body=CreateController(obj.height,obj.width,obj.step_height,obj.max_slope)

SetBodyMass(obj.body,1)
EntityType(obj.body,COLLISION_CHARACTER)

obj.head=CreatePivot()

refresh_mesh(obj,GetEntityKey(obj.model,"mesh"))
if obj.mesh==nil then
	obj.mesh=CreatePivot()
end
PositionEntity(obj.body,EntityPosition(obj.model))
PositionEntity(obj.head,EntityPosition(obj.model))
RotateEntity(obj.head,Vec3(0,EntityRotation(obj.model).y,0))
end

 

and on PhysicsUpdate

if obj.target~=nil then
	if EntityDistance(obj.body,obj.target)<.5 then
		get_next_point(obj)
		return
	end
	PositionEntity(obj.head,EntityPosition(obj.body))
	obj.head:Point(obj.target,3,obj.turn_smooth,0)

	obj.body:Update(EntityRotation(obj.head).y,obj.walk_speed,0,0,40,1,0)
end

PositionEntity(obj.mesh,EntityPosition(obj.body))
RotateEntity(obj.mesh,Vec3(0,EntityRotation(obj.head).y-180,0))

"Better" is big enemy of "good"

Link to comment
Share on other sites

if EntityDistance(obj.body,obj.target)<.5 then

 

You've never had any issues with this? I've had it before where if the computer lags then Update on the controller will shoot the controller well past it's target.

 

For now I'll do it that way, but just wasn't sure if there was a more precise way to avoid any lag issues.

Link to comment
Share on other sites

You've never had any issues with this? I've had it before where if the computer lags then Update on the controller will shoot the controller well past it's target.

 

For now I'll do it that way, but just wasn't sure if there was a more precise way to avoid any lag issues.

 

With this code walking 15 NPC at same time, and all is correct.

But it makes sense... will think about it.

 

Think at get next point we can store distance from current NPC position to it, and while move forward check not distance to target point, but length of way that passed NPC.

 

Like this:

 

       if obj.target~=nil then
               if EntityDistance(obj.body,obj.prev_point_pos)>obj.path_lenght then
                       PositionEntity(obj.prev_point_pos,EntityPosition(obj.body))  -- store prev point position
                       get_next_point(obj)
                       obj.path_lenght=EntityDistance(obj.body,obj.target)  -- distance to new target

                       return
               end
               PositionEntity(obj.head,EntityPosition(obj.body))
               obj.head:Point(obj.target,3,obj.turn_smooth,0)

               obj.body:Update(EntityRotation(obj.head).y,obj.walk_speed,0,0,40,1,0)
       end

       PositionEntity(obj.mesh,EntityPosition(obj.body))
       RotateEntity(obj.mesh,Vec3(0,EntityRotation(obj.head).y-180,0))

 

This can free such lag.

P.S. maybe this code is wrong, not checked, just concept.

Edited by Aily

"Better" is big enemy of "good"

Link to comment
Share on other sites

Is there a way to calculate how much the controller actually moves in a given frame? I know for example sake you say 7m but that would be a variable speed given speed of the app right?

 

How would I do that? Would I have to calculate the move variable that passes to the controller and if so what is that calc? Using any sort of MoveEntity or PositionEntity would stop the physics on it. Maybe we don't care for such a small amount but could that cause issues somehow?

 

I really wish LE had a MoveTo type of method :)

 

yeh AppSpeed()...

 

Well It depends how you move your controller. I don't use the LE Controller so I'm actually moving my controller by a physical distance every frame * AppSpeed()... Hence you calculate the '7m' by getting your distance*AppSpeed(). I'm not sure I know how the LE controller works but you could find out what the rate of movement at 60fps and then that would be your distance.

 

Didn't have time to read what Aily posted though. I've never actually done this. It's just how I would attempt to do it.

 

P.S. because the controller goes the same speed up hill and down and flat... you may want to not find the Entity distance in 3D space but rather in 2D space from top down.... as in the Z & X planes only.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...