Results 1 to 12 of 12

Thread: Simple Path Movement

  1. #1
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default Simple Path Movement

    OK. So, I have a sprite which I want to move up and down the play area. Applying some of the techniques I learned in the Dragon Eggs tutorial I setup two waypoints and applied the following script to the sprite:

    Code:
    function OnMapInsert() //run as the entity is placed on an actual map, but before OnPostInit()
    	GetWatchManager:Add(this, C_TIME_FOREVER); //always function offscreen
    end
    
    function OnInit() //run upon initialization
    	
    	//hint to the path-finding system that it can ignore this while computing paths if it needs to
    	this:SetIsCreature(true); 
    end
    
    function OnPostInit() //run after being placed on a map
    
    	this:GetBrainManager():Add("StandardBase","");
    	
    	AddPatrolGoals();
    	
    end
    
    function OnKill() //run when removed
    
    end
    
    function AddPatrolGoals()
    
    	//let's make him move to the four checkpoints
    	
    	this:GetGoalManager():AddApproach(GetEntityByName("Ele1B"):GetID(), C_DISTANCE_CLOSE);
    	this:GetGoalManager():AddApproach(GetEntityByName("Ele1A"):GetID(), C_DISTANCE_CLOSE);
    
    end
    The sprite is positioned at the top of the screen, as is waypoint Ele1A. Using this code I would hope for the entity to move down (to waypoiny Ele1B) the screen and back up.

    The problem is that there are some entities in the way, and the sprite attempts to maneuver its way around these entities (and eventually gives up when it reaches a solid platform). I though I could get around this by assigning the sprite to layer "Overlay 1", but this does not seem to help.

    Any ideas on what I can do to just bring this sprite up and down the screen?

  2. #2

    Default

    hi pleng,

    i'm no expert by any means, so take this for what it's worth, but you may have to set up more path nodes to give your sprite more choices of how to navigate to the way points, then it might not get hung up on obstacles.

    someone please correct me if i'm wrong.

    good luck pleng

  3. #3
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default

    Hi Harrio.

    Thanks for you response.

    Yes, adding pathfinding nodes will help the sprite move around obstacles. However I want my sprite to go directly from point A to point B, ignoring any obstacles. Think, as an example, of moving platforms in games such as Sonic the Hedgehog. These will follow a fixed path regardless of any other player, enemy, or other background obstacles which might be in the way.

  4. #4

    Default

    ok,

    i think i understand now. i misinterpreted what you were saying. you want a non-player entity to move on a fixed path. i think, you can have it ignore collisions, but you will have to deal with how it interacts with player entities, maybe by increasing it's density or simply being rendered over or under the players.

    hope that helps.

  5. #5
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default

    i think, you can have it ignore collisions,
    Ok thanks. How do I go about doing that?

  6. #6
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Hmm... well, one solution is to not give it enough nodes to make any 'choices' so a platform can't avoid anything.

    I threw a platform into the treeworld example to illustrate this. (see pic)

    Another option would be to handle the movement without using the pathfinding system - you could still use your same start/end marker tags, but handle the actual movement by calling AddForceConstant() each update tick.

    Warning: In general, the pathfinding stuff is not going to work with the sideview things as far as AI movement, as it doesn't understand things like ladders and jumping.
    Attached Images Attached Images  
    Seth A. Robinson
    Robinson Technologies

  7. #7
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default

    Thanks for your reply Seth

    Hmm... well, one solution is to not give it enough nodes to make any 'choices' so a platform can't avoid anything.
    Well I currently have 2 waypoints and no pathfinding nodes. The Entity still gives up when it hits a platform below it.

    If you see the attached screengrab, what I'm trying to do is to have the barrel move up and down between the two waypoints. As there's a platform in the way it just completely gives up
    Attached Images Attached Images  

  8. #8
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Ah, I see..

    Ok, you can fix this by getting entity to ignore all static collisions.

    In your version, you could do this by setting up the platform to 'listen' to static collisions and then return false (which invalidates) every collision in the OnCollisionStatic().

    But, a better way would be to download the latest version, it adds a few new collision modes so you could just do:

    this:SetCollisionMode(C_COLLISION_MODE_ENTITIES_ON LY);
    or
    this:SetCollisionMode(C_COLLISION_MODE_PLAYER_ONLY );

    This is faster than needing to deal with script callbacks.

    The internal waypoint system is built around A* pathfinding (if the nodes exist).. currently, if it can locate a way to get from A to B without going through walls, it will. Currently, there is no way to disable that if using the pathfinding stuff.

    Btw, targets/waypoints also act as pathfinding nodes, so if you have a lot of waypoints close together, it will route using them which may screw things up. Instead of using them, you might want to make your own version and comment out the parts in its script that make it operate as a pathfinding node.
    Seth A. Robinson
    Robinson Technologies

  9. #9
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default

    Ahhhh new collision modes. Reading the scripting reference I was thinking that a couple more would be useful but looks like you're already on the ball!

    Thank you for your persistence in helping me out here, by the way!

    I was playing around with C_COLLISION_MODE_NONE before and this didn't seem to be working, which confused me somewhat. Turns out I hadn't attached the script to the barrel, which was pretty dumb!

    Yes I'm not sure the waypoint system is going to work too well.

    One problem I'm currently facing are that the barrel seems to be affected by friction when it passes through the grass. I have managed to minimize this by adding this:SetDensity(3), this:SetDampening(0), and this:SetGravityOverride(0.3)

    But the big problem is that the barrel just can't find the connection nodes. No matter how many I place on the map, they will not connect 'through' the grass, so I get a lot of 'Unable to locate any connected nodes of type 1' and 'cannot find a path to to approach entity xxxxx, aborting'.

    Btw, targets/waypoints also act as pathfinding nodes, so if you have a lot of waypoints close together, it will route using them which may screw things up. Instead of using them, you might want to make your own version and comment out the parts in its script that make it operate as a pathfinding node.
    I tried looking in waypoint.lua, but all I found was this:

    Code:
    //standard waypoint
    
    function OnInit()
    
    		this:SetVisualProfile("~/system.xml", "waypoint");
    	this:SetMass(0); //makes it immovable, speeds up processing too
    end


    Anyway it looks like I'm going to need to write a new system. If you could be so kind as to point me in the right area of the scripting reference I'd be much obliged.

    Essentially I just need the barrel to move up and down the screen repeatedly, giving no regard to anything else on the screen aside from the player, who will die on impact.

  10. #10

    Default

    hey pleng,

    correct me if i'm wrong seth, but could pleng make use of the 'addmovetoposition' function/vector and a 'schedule' call to repeat the movement over a desired interval.

    i'm trying to wrap my own head around the scripting api, so i offered the suggestion to see if i'm on the right track.

    also...will i able to download the latest 'mar 21' version without losing my app/window pref settings and demo game listings?

    thanks for the continued work on this kickass engine.

  11. #11
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    But the big problem is that the barrel just can't find the connection nodes. No matter how many I place on the map, they will not connect 'through' the grass, so I get a lot of 'Unable to locate any connected nodes of type 1' and 'cannot find a path to to approach entity xxxxx, aborting'.
    Hrm, yes this is a problem, annoying having the log cluttered up with these. I'll think about this some more, like how useful it would be to be able to activate a 'dumb pathfinding' mode for an entity, for flying enemy movement patterns etc.

    I tried looking in waypoint.lua, but all I found was this:
    My mistake, actually it's not in the script, you need to edit the node entity from the editor, select properties, then uncheck the "Path node" option.

    correct me if i'm wrong seth, but could pleng make use of the 'addmovetoposition' function/vector and a 'schedule' call to repeat the movement over a desired interval.
    harrio, close - but actually AddMoveToPosition is going have the same problem that AddApproach does, it will internally try to pathfind to the position and give annoying warnings on the log if none are found.

    A better solution is probably to do it at a lower level with AddForce/AddForceConstant. I did a test and it worked ok, here is the script (assign to a tilepic that has collision data..)
    Code:
    //these are existing waypoints/named objects on the map
    m_tagA = "MyTagA"
    m_tagB = "MyTagB"
    
    m_closenessNeededToTarget = 50; //how close we need to to assume we reached our target
    m_speed = 3; //how fast we move
    m_curTargetPos = Vector2(0,0);
    
    function SetNewTarget()
    
    	if (m_curTargetPos == GetTagManager:GetPosFromName(m_tagA)) then
    		//well, let's go to B then
    		m_curTargetPos = GetTagManager:GetPosFromName(m_tagB);
    	else
    		//well, let's go to A then
    		m_curTargetPos = GetTagManager:GetPosFromName(m_tagA);
    	end
    	
    end
    
    function OnInit() //run upon initialization
    	this:SetGravityOverride(0);
      this:SetDampening(0);
      this:SetCollisionMode(C_COLLISION_MODE_PLAYER_ONLY);
      SetNewTarget();
    end
    
    function OnPostInit() //run during the entity's first logic update
    	GetWatchManager:Add(this, C_TIME_FOREVER); //always function offscreen
    	//let's have a function that gets run every logic tick
    	this:SetRunUpdateEveryFrame(true);
    end
    
    //this is run every logic tick
    function Update(step)
    
      //remove all movement, no momentum
    	this:AddForceConstant(this:GetLinearVelocity() *-1);
    	
    	//move towards target
    	this:AddForceConstant(this:GetVectorToPosition(m_curTargetPos)*m_speed);
    
      if (this:GetDistanceFromPosition(m_curTargetPos) < m_closenessNeededToTarget) then
       	//we reached out target!  Set a new one.
       	SetNewTarget();
      end
    
    end
    also...will i able to download the latest 'mar 21' version without losing my app/window pref settings and demo game listings?
    I want to test this and get back to you.. for now, I'd recommend copying your changed "worlds" to a temp dir before installing, then you can copy them back. (or you can run them from the temp dir actually, just double click the *.novashell file)

    The prefs are stored in prefs.dat, you could back this up too, and copy it back after installing. Although, this should NOT be required, as it's created only if it doesn't exist the first time you run the game.
    Seth A. Robinson
    Robinson Technologies

  12. #12
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default

    Thank you so much Seth!

    This is exactly what I needed.

    I have made a few changes to the script to allow unlimited waypoints, rather than just the two in your example (this I didn't actually need for my game... just wanted to test out my understanding of the script!) I will post the code on the Scripting Examples forum.

Similar Threads

  1. Relative File Path
    By Dr. Rain in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 03-08-2008, 01:05 AM
  2. Simple Animation
    By ares in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 02-27-2008, 05:20 AM
  3. simple ClanLib example problem - segfault
    By phx_one in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 02-17-2008, 12:54 AM
  4. Program Dies from Player Movement
    By catch22 in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 08-03-2007, 06:08 AM
  5. Simple app won't compile when linked with clanlib
    By mmiikkee12 in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 07-17-2007, 02:41 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •