GOOOAAAL!!

OK, let’s say I have a draggable rectangle and I want the player to complete a level if that rectangle is moved in front of a goal - which is another rectangle but just slightly larger.

How do I check if the rectangle object has been moved to the correct location - i.e. in front of the goal?

It also doesn’t have to be perfectly aligned, I want there to be a slight tolerance - about 10% or something.

I’ve been playing around and trying to get this working for longer than I want to admit so I’d be very thankful to anyone who can help out with ideas and/or sample code.

Thanks in advance all [import]uid: 74503 topic_id: 14199 reply_id: 314199[/import]

put an invisible sensor in front of the goal
let this sensor fire an collision event when it is touched by your rectangle
define a litte bigger rectangle “goal area”
if the event is fired check if all corner points of your draggable rectangle are in the “goal area”

the “goal area” can act as the sensor
this should work, mabye it’s optimizable

maybe you can put there 4 circle sensors for the corner points of your rectangle - if all sensors fire at the same time you have a goal [import]uid: 70114 topic_id: 14199 reply_id: 52315[/import]

I think the Air hockey sample code does what you need. Check it out. [import]uid: 13560 topic_id: 14199 reply_id: 52320[/import]

@Sven.Lua That sounds like what I’m after I think

How would I check that all the corners of the rectangle are in the goal area though?

Cheers [import]uid: 74503 topic_id: 14199 reply_id: 52323[/import]

another way…

maybe its easier to check if the center of the rectangle is near to the center of the goal area and the rotation angle of the rectangle is near 0 or near 180

Can you do it this way? [import]uid: 70114 topic_id: 14199 reply_id: 52327[/import]

Very helpful sir.

That sounds very possible. I shall get coding and see what I can come up with using your suggestions.

Many thanks Sven.Lua
I’ll still leave the floor open for anyone else to chip in with samples or other ideas though on this one - it can only help. [import]uid: 74503 topic_id: 14199 reply_id: 52330[/import]