Detecting collision sides

foldifoldi Member Posts: 21
edited November -1 in Working with GS (Mac)
Is it possible to detect which side caused a collision? For example, actor 'player' falls on actor 'enemy' from above. That should trigger a different behavior than if actor 'player' runs into actor 'enemy' from the side.

I understand I could create hidden actors that are constrained to the location of the enemy. This would make sense if there was one enemy. But if there is an unlimited amount of enemies that can be spawned and destroyed, how could the hidden actors access their parent enemy's XY values?

Comments

  • jstrahanjstrahan Member Posts: 498
    When collision Happens subtract actor 1 position from actor 2 position if result is >0 hit from one side if <0 hit from other side
  • foldifoldi Member Posts: 21
    Great. That makes sense. But how does can I access actor 2's position? From what I understand, actors do not have access to other actor properties.
  • jstrahanjstrahan Member Posts: 498
    If it's not spawned it's in current scene.layers.(whatever layer the actor is in).(actor2 name).position.(x or y)

    If it is spawned let me know and I'll tell u how it's a little more work
  • jstrahanjstrahan Member Posts: 498
    If it's spawned make an attribute posx and posy then in actor make rule that when collide change attribute posx and posy to actor position x and y then in actor 1 compare actor 1 position to posx and posy
    The only problem is u you need a posx and posy for each actor on screen at one time plus track witch actor goes with which posx posy combo which can b done but takes alot of rules
    I have a game I'm wrkn on that uses this way and has a ton of rules
  • foldifoldi Member Posts: 21
    Ok. I'm using the attribute browser to access attributes but do not see the path scene.layers.actor.etc.... is this referenced via the attribute browser or just typed directly in the expression editor?
  • jstrahanjstrahan Member Posts: 498
    Double click on actor on game scene unlock it then make all changes there for now on
  • jstrahanjstrahan Member Posts: 498
    Or top left click scene then expand the background layer and double click actor
  • millerbrother1millerbrother1 Member Posts: 108
    Great post guys.

    What if the logic I want to employ for this cannot be "scene specific" meaning it will have to continue throughout the duration of the game and I want to make all my edits in the prototype actors, not in the scene logic. (Reason: there will be too many scenes to modify the logic in if I need to change it).

    Here are the rules I'm trying to figure out:

    I have inanimate objects that can destroy (or damage in my case) an enemy if it lands on his head, but not if he is perched on them. (Think Angry Birds boxes).

    In this case I have a prototype "box" actor that I can stack a bunch of and when/if the Hero causes the box to collide with the "enemy" actor it needs to follow this logic (spoken in the context of the enemy actor):

    IF an "actor of type" BOX collides with me on "MyHead" THEN decrease my health (or destroy me if I have no health left).

    Also, the same enemy actor has to have the following logic when attacked/hit by the player.

    IF the player collides with "MyBackside" or "MyHead" THEN destroy the PlayerActor. Otherwise if the player collides with Me (meaning my face or belly) THEN decrease my health (or destroy me if I have no health left).
  • jstrahanjstrahan Member Posts: 498
    u will have to have global x,y values and constrains for every object which would b alot of attributes and way to much constraining so doing it at scene level would b easier bc the x,y values or already there and better profromance
  • JackBQuickJackBQuick Member Posts: 524
    I tried to find a demo to help you -- I could have sworn somebody made one -- but I couldn't. So, I quickly threw this together for you:

    Collision angle

    Cheers!
  • foldifoldi Member Posts: 21
    Jack,
    Thanks for responding... your example above solved the problem!
Sign In or Register to comment.