How do I make multiple instances move to different places?

0 favourites
  • 9 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • I need my instances to patrol two points that are spawned by them when a timer goes off.

    Eg: Instance created, Instance is static, Timer goes off, Instance spawns two points(A and B)close to it, and then it begins moving between the two.

    My problem occurs when another Instance is created, it spawns two points of it's own but just follows the old points created by Instance 1, thus colliding with Instance 1, and basically just patrolling Instance 1's route.

    I've also tried a method I saw in the forums, where using a bullet behavior the Instances move randomly through a number of points.

    I'm not looking for that type of behavior, as the instances overlap each other frequently, and the points are not really random.

    Can I get some help?

    Thanks.

  • Well, tbh it's a bit difficult to tell. I'm inclined to think your objects are confused about which objects they patrol between, but without more information it's just guesswork.

  • You need to make sure each spawned Point knows who it's parent is. Add an instance variable for the ParentUID, and set it to the parent's UID. Then just do a "Pick by comparison" of the Points with the appropriate Parent ID and perform your patrol code.

  • I don't whink you need some kind of special behavior to do it... I did something similar in our very first game: http://lucho.octetostudios.com/

    Maybe you will not understand the instructions because it's in spanish, but the idea of police patrolling is what I think you are looking for.

    Basically what we did was that every police has an instance variable called "name" (police01, police02, etc). The patrol between points (A and B) have an instance variable called "forPoliceName" (police01, police02, etc). So, this way the patrolling points belongs only to one police instance. Then you patrolling method has to evaluate if the patrolling point belongs to the police you are moving or not and then move to it or another if the condition matches or not.

    In that game, we have several police instances and every police has several patrolling points and it works perfect. Even the patrolling path changes to you if you get caught entering to a house. The police starts following you for a limited period of time and then it gets back to its original patrolling path. Take a look at it a tell me if it helps <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • You need to make sure each spawned Point knows who it's parent is. Add an instance variable for the ParentUID, and set it to the parent's UID. Then just do a "Pick by comparison" of the Points with the appropriate Parent ID and perform your patrol code.

    I tried your method, and it worked for one of the instances(it followed the waypoint created by it), but the other instance that was created later just froze. I debugged the game later and found out that the latter instance didn't spawn a waypoint with its parent ID, so it just stood there. <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    I don't whink you need some kind of special behavior to do it... I did something similar in our very first game: http://lucho.octetostudios.com/

    Maybe you will not understand the instructions because it's in spanish, but the idea of police patrolling is what I think you are looking for.

    Basically what we did was that every police has an instance variable called "name" (police01, police02, etc). The patrol between points (A and B) have an instance variable called "forPoliceName" (police01, police02, etc). So, this way the patrolling points belongs only to one police instance. Then you patrolling method has to evaluate if the patrolling point belongs to the police you are moving or not and then move to it or another if the condition matches or not.

    In that game, we have several police instances and every police has several patrolling points and it works perfect. Even the patrolling path changes to you if you get caught entering to a house. The police starts following you for a limited period of time and then it gets back to its original patrolling path. Take a look at it a tell me if it helps <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    This is sort of what I am looking for.

    Could you perhaps explain further in detail?

    Thank you.

  • > I don't whink you need some kind of special behavior to do it... I did something similar in our very first game: http://lucho.octetostudios.com/

    > Maybe you will not understand the instructions because it's in spanish, but the idea of police patrolling is what I think you are looking for.

    >

    > Basically what we did was that every police has an instance variable called "name" (police01, police02, etc). The patrol between points (A and B) have an instance variable called "forPoliceName" (police01, police02, etc). So, this way the patrolling points belongs only to one police instance. Then you patrolling method has to evaluate if the patrolling point belongs to the police you are moving or not and then move to it or another if the condition matches or not.

    >

    > In that game, we have several police instances and every police has several patrolling points and it works perfect. Even the patrolling path changes to you if you get caught entering to a house. The police starts following you for a limited period of time and then it gets back to its original patrolling path. Take a look at it a tell me if it helps <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    >

    This is sort of what I am looking for.

    Could you perhaps explain further in detail?

    Thank you.

    Give me a couple of days to me find the C2 project to remember all the details and explain a little more or maybe post and image of a piece "of code" ... it was a long time ago...

  • (You need LiteTween).

  • blackhornettechnologies.com/Construct2Stuff/PatrolExample.capx

    (You need LiteTween).

    Thank you. This helped alot.

    Although while trying to reconstruct it, I ran into some problems.

    First off, upon creation 'Sprite' starts moving on it own, without the waypoints. After the waypoint creation it moves along well though.

    This is a bit problematic because sometimes the 'Sprite' moves all the way off screen.

    Secondly, I did not understand the first two lines of events and thus while recreating it, I made them up myself.

    I'm thinking that is the reason I'm having the first problem.

    Could you explain the first two lines of events for me?

    I understood the 'at start of layout: destroy instances' event, but I did not understand the sub event.

    Could you please explain it to me?

    Thank you.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The sub-event is just placing three sprites randomly on the screen, and starting their individual timers with a random timeout.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)