Actor skips to follow a rule random

Hello everybody

I have set up a scene where a 1st actor spawn a 2nd actor 10 times into the scene itself at a random rotation, once I did that the 1st actor gets destroyed and the other 10 are setup with an animation and to start moving around the scene in which if they touch the scene boundaries that I setup or some stuff within the scene they will rotate and move to a random direction away from those objects. This works fine fore some events but at some point in a random manner some of the 10 actors start walking over the objects instead of bouncing against them, if I let the scene play for a long time eventually all the 10 actors would do the same I have tried to make the movement in different ways with timers or change direction etc but at the end it tends to make the same.

if anybody has a solution to it or a better way to do a "random walk" with bouncing on walls and objects I would appreciate your comments.

Thanks

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2016

    "if anybody has a solution to it . . . "

    There are probably errors in your code / logic ? Without access to your code, or knowing anything about how the code is set up there's not a lot people can do to help.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Are you using the physics engine? This will allow for collisions. Certain behaviors like using a constrain or change attribute in relation to position override the physics engine with nullifies the collisions. Also when using collisions uncheck "can sleep" and check "better collisions"

  • stringel.abelardostringel.abelardo Member, BASIC Posts: 4

    thanks for your quick reply, I have attached a file that shows my coding perhaps this can help you guys help me out but I can not upload it. I am new to the forum how can I share my coding haha.

  • stringel.abelardostringel.abelardo Member, BASIC Posts: 4

    The blue guys are supposed to bounce off the level walls according to a random angle that should make them go back inside the scene and the pink objects are just around the scene and when the blue guy touches it they must go back 180 degrees. As you can see one of the guys jump off the pink part and now is wandering on the right side of the scene and other guy is about to leave the scene on the upper wall.





    The change attribute says self.wnBettaRotation- self.wnBettaRotation+random(-45,45)
    The change attribute says self.wnBettaRotation- self.wnBettaRotation+random(235,315)
    The change attribute says self.wnBettaRotation- self.wnBettaRotation+random(135,225)
    The change attribute says self.wnBettaRotation- self.wnBettaRotation+random(45,135)

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2016

    @stringel.abelardo said:
    The blue guys are supposed to bounce off the level walls according to a random angle that should make them go back inside the scene and the pink objects are just around the scene and when the blue guy touches it they must go back 180 degrees.

    I had a quick look through your code and although there is nothing obvious that would cause the issue of actors passing through walls, there is certainly a lot of unnecessary and inefficient code, which may well be contributing to the issue . . . .

    For example:
    change self.wnBettaRotation to
    self.wnBettaRotation- self.wnBettaRotation+random(-45,45)

    With this you are changing A to A-A + a random value

    . . . and as A-A = 0 . . . that means . . . 0 + random value . . . is simply random value.

    So the whole rule could simply be:
    change self.wnBettaRotation to random(-45,45)

    But then you use a Rotate To behaviour to rotate the actor to this newly generated 'self.wnBettaRotation' angle.

    But could you not have simply Rotated the actor to random(-45,45) in the first place ?

    Does that make sense ?

    This:

    Change self.wnBettaRotation to
    self.wnBettaRotation- self.wnBettaRotation+random(-45,45)
    Rotate To self.wnBettaRotation

    Vs:

    Rotate To random(-45,45)

    They both do the same thing.

    Anyhow, there seems to be a few approaches like this throughout the code, giving GS a lot of unnecessary calculations and work to do when it hits a wall, another example would be that it is constantly checking if it is hitting all four walls, but of course if it's hitting the upper wall it can't be hitting the lower wall on the same frame.

    Your code structure is this:

    If I hit A - do some stuff
    If I hit B - do some stuff
    If I hit C - do some stuff
    If I hit D - do some stuff

    You could structure your code like this (nested) . . .

    If I hit A - do some stuff
    Otherwise
    --If I hit B - do some stuff
    --Otherwise
    ----If I hit C - do some stuff
    ----Otherwise
    ------If I hit D - do some stuff
    ------Otherwise

    In the second example if - for example - the actor hits B, it won't need to check whether it also is hitting C and D, or if it hits A it won't then check whether it's also hitting B, C and D . . . etc.

    Also . . . there's an obvious edge case here . . . as all your code is scanned together, in one frame, the actor could have overlapped with - for example - the right side wall, it is then angled (instantaneously) by your code such that it is still overlapping with the right side wall . . . and crucially . . . is now also overlapping with the upper wall, the upper wall could then rotate it so that the direction it's facing will send it back towards the right side wall and - as it is currently overlapping with the right side wall already - no collision will be detected (for a rule to be triggered a state must change), so it will just pass through the right side wall.

    Just some suggestions . . . .

  • SocksSocks London, UK.Member Posts: 12,822

    @stringel.abelardo said:
    The change attribute says self.wnBettaRotation- self.wnBettaRotation+random(-45,45)
    The change attribute says self.wnBettaRotation- self.wnBettaRotation+random(235,315)
    The change attribute says self.wnBettaRotation- self.wnBettaRotation+random(135,225)
    The change attribute says self.wnBettaRotation- self.wnBettaRotation+random(45,135)

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2016

    This simplified approach (attached below) works just fine, the actor never breaks through the walls.

  • stringel.abelardostringel.abelardo Member, BASIC Posts: 4

    awesome thanks, at the beginning I was using a very simple code but the actors keep overriding the rules so I just blast it with a heavy approach trying to be more specific to GS I guess my experience tough of it as a good idea but now that I read your comments it all makes sense there got to be some times that the rule by itself will not work if the actor is already overlapping a wall when giving a command to go that way.

    I will try your suggestions with the nesting code and the one you attached.

    Thanks a lot I really appreciate the support, what a great forum.

Sign In or Register to comment.