Get actors to move with the actor they collided with?

pixel_knightspixel_knights Member Posts: 50
edited April 2012 in Working with GS (Mac)
Hi all,

I'm working on a project where actors of a given type are spawned and drop from the top of the screen. These actors collide with other actors which stop them in their tracks, the dropped actors then rest on the other actors. However, the problem I have is creating a type of platform actor which moves, and takes whatever else is on it with it. Since i'm spawning and there could be multiple platforms, I don't know which platform an actor has landed on? I checked in the rules, and I can setup a rule for when it has collided, but none of the functions (so that I can constrain) seem to let me constrain to the item it collided with.

Think of it as eggs falling from the sky, landing in a frying pan, of which there can be a few on screen, some move, some don't. If they land in a moving one, I want it to move all the eggs (which could be stacked on top of each other too) along with it.

Can anyone offer any advice or know of any examples which work like this?

Thanks

Best Answer

  • tatiangtatiang Posts: 11,949
    Accepted Answer
    One way to achieve this is to have game.panX and game.panY real attributes and have a rule in the frying pan actor that says When colliding with actor egg --> constrain game.panX to self.position.X and game.panY to self.position.Y. If your pan is moving, the egg will hit it and move with it. You may need an offset (x+20, y+5 or whatever) if you don't want the egg to constrain to the center of the frying pan actor.

    The issue with this solution is that I'm not sure what will happen when multiple eggs hit multiple frying pans. Chaos for sure!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • pixel_knightspixel_knights Member Posts: 50
    Yes, that's the problem I had with trying that too, also trying to keep track of when eggs land on top of other eggs which have landed on pans. Ideally it would be nice if in the colide rule, GS gave you access to the properties of the object you've colided with.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    There are ways to get around this. I haven't fully tested it, but you can have each actor timestamp itself when it collides (change attribute self.collideTime to game.Time) and then check times to see if they both collided at the same time, or you can have the egg actors have self.IDs and then when the eggs collide, they change game.currentCollisionID to self.ID and the frying pan then knows which egg collided by checking game.currentCollisionID. Obviously, neither of these is a perfect solution!

    And you CAN unlock actors so that they have access to each other's attributes without the need to use game-level attributes to pass information. It's not quite the same thing as what you're asking for (e.g. collidedActor.position.X), but it's a start.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.