How detect colision with primitive drawing?

Hey there! I have a problem, i need to detect a colision with the rectangle created with primitive drawing and some sprites. I want to create a selection rectangle to catch sprites and then make things with this selected objects.

If rectangle is in colision with chars change animation of chars to 1.

something like this. but i cant. how i can solve this? :frowning:

[size=85]
PS.: my rectangle is created when i click with tle left button and then i create an object to mark the initial point. so, if i press left the rectangle is create with the X and Y of this Mark-object and the X and Y of mouse. [/size]

Hi, in theory you can make your own simple “box collision system” using the data you provided, which I bolded.
Make sure to record this data into variables.

You should have variables:

So here is what the variables will store:

Now how do we check if anything (e.g. an object) is inside this box? Easy to do simply, difficult to do accurately.

Simply, make some compare two expression block conditions (in “Other” actions) and add something like:

if Object1.X() > Variable(BoxXStart)
if Object1.X() < Variable(BoxXEnd)
if Object1.Y() > Variable(BoxYStart)
if Object1.Y() < Variable(BoxYEnd)

(These conditions must be together in the same event, only if all are valid, then our object is inside of the box in all axes)

On the right/action side, add whatever you like, e.g. change animation action.

This should work, but will consider only the starting point of the object (top left corner) for collision check. You can use the center instead by using these conditions:

if Object1.PointX(Centre) > Variable(BoxXStart)
if Object1.PointX(Centre) < Variable(BoxXEnd)
if Object1.PointY(Centre) > Variable(BoxYStart)
if Object1.PointY(Centre) < Variable(BoxYEnd)

This should make it activate the “collision” only when your object’s center part is inside the box. You could make it even more complicated by adding some box “radius” so that both center+corners are detected.

Then the conditions would be:

if Object1.PointX(Centre)-Variable(RangeX) > Variable(BoxXStart)
if Object1.PointX(Centre)+Variable(RangeX) < Variable(BoxXEnd)
if Object1.PointY(Centre)-Variable(RangeY) > Variable(BoxYStart)
if Object1.PointY(Centre)+Variable(RangeY) < Variable(BoxYEnd)

The goal of this is to add an invisible “wall” around the center point of object to get more accurate rectangle collision check.

Make sure to calculate this:
Object sprite (image) width divided by 2 in calculator (e.g. 512/2=256), and save the calculated value into “RangeX”
Object sprite (image) height divided by 2 in calculator (e.g. 256/2=128), and save the calculated value into “RangeY”.