Detect Collision on actor (from direction)

NMansellNMansell Member Posts: 143
edited August 2012 in Working with GS (Mac)
is there a way to detect where the collision on the actor occured, so if I have a square box in the centre, if another actor hits it I can detect whether it was hit from top, bottom, left or right?

Comments

  • MotherHooseMotherHoose Member Posts: 2,456
    edited August 2012
    on collidingActor:
    in the Rule for collides with box
    another Rule in the behavior area
    … when self.PositionX > box.Position.X
    then it is a rightSideHit …Otherwise: when < … it is leftHit
    … when self.Position.Y > box.Position.Y
    then it is a topSideHit … Otherwise: when < … it is bottomHit

    add gameAttributes to store hitValues
    and use those values for rule conditions for actions after collides

    ==
    though might be easier to create a sensorActor
    drag 4 instances to scene … name appropriately: top, bottom, right, left

    add gameAttribute … text type … hitArea

    sensorActor prototype:
    Rule: when
    Event: overlaps/collides with other actors
    -changeAttribute: game.hitArea To: self.Name

    Rule: when
    Attribute: game.hitArea is top
    -do top actions

    4 rules for the 4 possible hitAreas

    when the action is completed:
    … be sure to changeAttribute: game.hitArea To: (and leave it blank)


    image MH
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
Sign In or Register to comment.