Detect Collision on actor (from direction)
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
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)
http://www.jamie-cross.net/?p=607
Jamie
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page