Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

2D Collisions

Name: Anonymous 2012-12-17 6:09

Help me out. I'm having trouble with 2 Dimensional collision detection in ActionScript 3.

public function isCollidingWithObject (other : GameObject) : Boolean
{
return ( Math.abs((this.position.x + (this.width / 2)) - (other.position.x + (other.width / 2) )) <= this.width + other.width
&& Math.abs((this.position.y + (this.height / 2)) - (other.position.y + (other.height / 2) )) <= this.height + other.height);
}


Why the fuck doesn't this work, I don't understand.

It keeps colliding 40 pixels too early.

Name: Anonymous 2012-12-17 6:16

I puked a little in my mouth.

Name: Anonymous 2012-12-17 6:21

Well that doesn't answer anything at all.

Name: Anonymous 2012-12-17 6:28

>>1
Why the fuck do you add dimensions/2 to positions when you try to determine distance between positions?

Name: Anonymous 2012-12-17 6:30

>>4
To get the center of the Object.

x is the left, x+(width/2) is the center
y is the top, y+(height/2) is the center

Name: Anonymous 2012-12-17 6:36

>>3
I'm telling you you're approaching the problem all wrong. Read SICP.

Name: Anonymous 2012-12-17 6:42

>>6
You're still not helping me at all

Name: Anonymous 2012-12-17 6:49

>>7
SICP would!

Name: Anonymous 2012-12-17 7:00

SICP doesn't say shit about geometrical programming

Name: Anonymous 2012-12-17 7:05

>>9
It does. Read it.

Name: Anonymous 2012-12-17 7:17

>>9
You have to reach SATORI first, then you will understand everything.

Name: Anonymous 2012-12-17 7:18

So, any chance the width of both your objects is 40 pixels too? =)

Name: Anonymous 2012-12-17 7:25

>>12

No. one is 15x15, other is 100x50

Name: Anonymous 2012-12-17 7:31

ah, still try ... (this.width + other.width) / 2

Name: Anonymous 2012-12-17 7:32

DON'T HELP HIM!!!

Name: Anonymous 2012-12-17 7:36

>>15
Why not?

>>14
Thanks, will try

Name: Anonymous 2012-12-17 7:37

>>16
mailto:nokonoko
( ≖‿≖)

Name: Anonymous 2012-12-17 7:43

>>17
wtf I didn't even do that

Name: Anonymous 2012-12-17 7:52

>>15 it is left as a challenge for the reader as to why this is (possibly) the correct answer...

Name: Anonymous 2012-12-17 7:58

>>18
Just like Abelson didn't steal the precious course, right?

Name: Anonymous 2012-12-17 10:19

>>19
Clearly it is a challenge up with which he will not put!

Name: Anonymous 2012-12-17 10:32

2Dubs

Name: Anonymous 2012-12-17 17:56

>>22
The imageboards are calling.

Name: Anonymous 2012-12-17 23:33

>>23
I don't have a phone.

Don't change these.
Name: Email:
Entire Thread Thread List