Objects recognizing when another object is nearby

Get help using Construct 2

Post » Sun Jul 14, 2013 10:15 pm

Actually you can replace the 'Create/Set position' with a Spawn, to save a step. Also the ColDetUID instance-variable on the Car isn't used and can be removed.
ImageImageImage
B
71
S
21
G
211
Posts: 3,613
Reputation: 119,145

Post » Sun Jul 14, 2013 10:56 pm

[quote]I'm going to have a lot of these sprites in my game at once, so it'd be nice if I didn't have to compute distance between all of them each tick. I thought the overlaps on offset was perfect, but I guess not?[/quote]

I'm honestly not sure that overlap is less expensive than distance checking.
To check the distance between two points, the formula is (and it's what c2 use):[code]distance(xa,ya,xb,yb) = sqrt((xa-xb)^2 + (ya-yb)^2)[/code]
basically you have 4 multiplications, 1 addition and one square root operation.
The square root operation is known to be a bit slow

Now for an overlap check, depending on the complexity of the shapes and the fact that they are rotated or not, it can be easy, or less easy.
But the basic "quad is overlapping quad" function more or less check if one is contained inside the other, and then if not, it checks if there's an interesection between each segments.
The operations used are fairly simple but it something of the order of
"number of vertices of object A TIMES number of vertices of object B"
So it can get pretty iffy.

Now, the only thing that is a bit unknown here is the speed of a square root operation. But you know, you don't even have to use a square root, you can yourself check if:[code](xa-xb)^2 + (ya-yb)^2 < someDistance^2[/code]Then you have your cheap distance check.Yann2013-07-14 23:07:23
B
64
S
22
G
14
Posts: 1,482
Reputation: 16,457

Previous

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, ColombageEnPLS, doriHOG, mrtumbles, rustomatic and 3 guests