Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to make an actor's collision field smaller than it's image?

homelesswombathomelesswombat Posts: 73Member
edited November -1 in Working with GS (Mac)
Boy that would save me a lot of work. And make my games nice and purty.


  • BeyondtheTechBeyondtheTech Posts: 809Member
    The only way it's possible is by having an invisible Actor that's constrained to the real Actor's position. Size the invisible one smaller and put the Collision Rules in there.
  • ORBZORBZ Posts: 1,303Member
    Ya i thought of that too BT, but what if you have more than one actor? What if they are dynamically generated?

    If they are static i.e. you have a fixed amount of them, you can bind them in your scene layer. But if they are dynamic i.e. created/destroyed on the fly, it gets a lot more complex.

    I don't have a good solution for that as I too have tried to find one.

    The best I can suggest, and this is by no means perfect. Is to use the change size attribute to grow your actor a little bit. The collision rectangle doesn't change when you use change size, or rather, shouldn't. I'm having all kinds of glitches with it on 0.8.2 though, It used to work that way on 0.7.0. They may have changed it.
  • BeyondtheTechBeyondtheTech Posts: 809Member
    I would then do a collision with a magnitude calculation.
  • homelesswombathomelesswombat Posts: 73Member
    I like the Change Size idea, that sounds like it would work really smoothly. Too bad it's buggy in 0.8.2 though.

    To be honest I'm amazed that the collision field and the image are the same thing. If there are any devs reading this, I think the image and the collision field being separate variables should be a standard feature (even if the collision fields are still restricted to being circular and square). Such a feature would adds a lot to games visually and in terms of playability. As it is right now it is really tough to make things look like they are actually touching each other, because there is always this little white space between them (unless the image is perfectly square or circular). From a player's standpoint, you always have to kind of "guess" by eye where the collision takes place, making dodging things, touching things and coordinating movement difficult.

    So if there's a 0.8.3 on the way, pleeeeeeeeease put that in!
  • firemaplegamesfiremaplegames Posts: 3,206Member
    I would do it like this:

    Create an invisible actor, a square or circle the size that you need the collision size to be. This is what the player controls.

    Create your graphics Actor, which has all the art/animations in it. This can be any size.

    Create two global real game attributes called playerX and playerY.

    Within the invisible actor, constrain those two global attributes to self.PositionX and self.PositionY
    Spawn the graphics actor from within the invisible actor.

    Within the graphics actor, Constrain self.PositionX to game.playerX and self.PositionY to game.playerY. If you need to, you can also include an X or Y offset here as well.

    I have used this and it works perfectly.

    Hope this helps!
  • design219design219 Posts: 2,273Member
    This is something I would really like to see in a future release. REALLY LIKE TO SEE.
  • quantumsheepquantumsheep Posts: 8,188Member
    It's useful for shooters - smaller collision boxes = more fun! :)

    Dr. Sam Beckett never returned home...

  • ORBZORBZ Posts: 1,303Member
    Good idea BT.
  • JGary321JGary321 Posts: 1,246Member
    Groin Shot!
  • homelesswombathomelesswombat Posts: 73Member
    I hear what you're saying firemaple, but that solution is only really feasible if you have a few simple actors. If there are dozens of instances of the same actor as in a typical side scroller level, it becomes a programming nightmare because you'd have to create x and y global variables for each individual actor. And that's not even getting into animations, spawning and everything else that makes a game good. They just need to make image and collision field separate variables within each actor and it makes the whole thing simple.

    I'm interested to hear more from BT. What's a magnitude calculation? How would the programming look?
  • homelesswombathomelesswombat Posts: 73Member
    Also, ORBZ I tried your Change Size idea and it appears that the collision field changes with the size now.
  • EastboundEastbound Posts: 1,074Member, BASIC
    Seems to me that you could make a rule with ALL the parameters needed:

    If there is a collison with object blah
    If object blah.x < self.x+10
    If object blah.x > self.x-10
    If object blah.y < self.y+10
    If object blah.y > self.y-10

    This would essentially work as a 20 by 20 collision box I think. It's like a square magnitude function.
  • ORBZORBZ Posts: 1,303Member
    Magnitude is another way if saying distance.

    So if when two actors collide you take the magnitude of their x/y positions you should be able to do some math to see if the length is less than the radius.

    However, I'd rather collision rect & image rect be diff attribs.
  • homelesswombathomelesswombat Posts: 73Member
    Okay thanks Eastbound, I get it now. But what if there are multiple instances of object blah? If you constrain objectblah.x and objectblah.y as global variables does Game Salad automatically make multiple instances of those global variables? Or will the system crash because one variable is being constrained to multiple arguments?
This discussion has been closed.