Beam Weapon Collision Detection

Post your own tutorials, guides and demos.

Post » Mon Apr 20, 2009 5:54 am

Hey, I'm making a beam weapon and it's length needs to be rather long 10000+ pixles.

And it's needs to cut down it's length if it hits an object.

I can do this: collision with blah blah: set width to distance(x1, x2, y1, y2) etc.

The problem is when it is a near miss the frame rate chugs down to less than 1! I know, my laptop, not a gaming machine.

But I was wondering if there was any better way to do it. Angle detection or something. Any ideas?
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Mon Apr 20, 2009 10:56 am

I don't understand why, but this makes my uber-rig cry (I get down to less than 1fps as well)... Something is seriously wrong with this cap, and I can't put my finger on it yet. going to try something now and see how it fares.


*EDIT*
As far as I can tell, there has to be a bug somewhere in this cap. It seems to be realted to your lerp call in the second to last event. I don't know enough about lerp to check your forumla, but the problem seems centred aroung that particular event.

I've had no luck in pin-pointing the exact cause, maybe someone else will have better luck, but I would be prepared to ready this for tracker submission as a bug if nobody else can suggest a solution.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
45
S
17
G
37
Posts: 2,853
Reputation: 25,966

Post » Mon Apr 20, 2009 12:46 pm

Have a look at this, it might help.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Sun May 03, 2009 11:27 am

Use the bullet behavior not one massive sprite for hit detection.
B
2
S
1
G
4
Posts: 33
Reputation: 1,266

Post » Sun May 03, 2009 3:35 pm

Like Max said - you could create a bullet sprite the same width as your beam, facing in the same direction, and just make it, say, 200 pixels long. Then you could give it the Bullet behaviour, make it Instant Hit, and set the speed to 200.

Instant Hit just keeps looping in the same tick until it hits something, so it'd strike the target immediately. If it traveled 10,000 pixels at the size and speed I said above, I guess that'd be, what, 50 loops? Should be no problem for the CPU.
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Mon May 04, 2009 12:03 am

You could do that, but the collision would only be accurate to the nearest 200 pixels, which is quite a large error. You might want to use a smaller object (maybe 30x30) and have a shorter maximum distance to save CPU (is your layout really going to need you hitting things 10,000 pixels away??)
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests