Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 17th Oct 2011 22:55
Aside from my frame rate issues, for a while I've been having trouble regarding collision with my player sprites and the enemy/bullet sprites. I decided to settle with circular collision for them. However, I want my enemies to shoot lasers from time to time.
http://www.youtube.com/watch?v=phdXS2kOmAw
This is basically what I'm looking for.
http://www.youtube.com/watch?v=m8mpyyjiE5M
And this is the kind of flexibility I need it to have.
Would anybody happen to have any advice on the math I'd need to use to achieve collision like the above two examples? If someone could at least tell me what kind of math to look for (or even better, point me to an equation) I'd be very thankful.
(I'd like to be able to control the width of the laser as well as the enemies won't be using the same size lasers)
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 18th Oct 2011 00:19
1. Check for the angle between the possible target, and the laser's center (use the ATANFULL() command)

2. Learn how to determine an ellipse shaped collision circle around the laser's center, at any angle the laser is rotated. It can be achieved with sin() / cos(), or maybe easier by using the NEWXVALUE(,,) and NEWZVALUE(,,) commands. (use newZvalue() for the Y onscreen, it's important not to use newYvalue(), it won't work properly!)

It's basically a circular collision system you are already using but with a rotated ellipse. As i imagine you would have absolute control over the laser's angle, length and width too. It's also pretty sure that they used the same technique in that game.

Check for the ellipse's radius at the angle towards the target, and the distance between the target's central position from the laser's central position. As with the standard circular system, if the "TARGET CENTER - LASER CENTER DISTANCE" is less than the "TARGET'S RADIUS + LASER'S RADIUS", a collision is occuring between the two.

I think with a bit of thinking you may understand this and reach the solution, sorry i have no time now to write the code piece.

-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 18th Oct 2011 01:03 Edited at: 29th Oct 2011 19:08
Thanks Quel! I do indeed understand what you're saying.

That being the case, I just need to write the code with ellipses in mind. (If I manage to figure it out I'll post it here for others to see too. Unless someone else wants to beat me to the punch which would also be appriciated. Thanks in advance.)

[Two weeks later]

Okay, so I now have collision for the ellipse but I'm having trouble rotating the ellipse (shaped collision). Whatever I try either expands the ellipse or makes it smaller.

As Quel said, check to see if "Target Center + Laser Center <= Target Radius + Laser Radius"
This is my equation and a couple components.

ttl# = atanfull(psx-cx#,psy-cy#)
(psx and psy are the player x and y positions)
(cx# and cy# are the laser's centers)

ra2# = sqrt((xradius#*sin(ttl#))^2+(yradius#*cos(ttl#))^2)
(this is the radius of the ellispe given the angle of the player and the laser multiplied by the initial x and y radiuses (is radii the plural?) of the laser)

if (cx#-psx)^2+(cy#-psy)^2<=(ra2#+30)^2
(perform action demonstrating collision)
dx#=psx-cx#
dy#=psy-cy#
angle#=atanfull(dx#,dy#)
x# = newxvalue(cx#,angle#,(xradius#+sin(ttl#)))
y# = newzvalue(cy#,angle#,(yradius#+cos(ttl#)))

ink rgb(255, 255, 0), 0
circle x#, y#,20
text 10, 10, "Collision Type 7!"
endif


I used bits and pieces from this code to "draw" the ellipse (to use as a visual for the collision. Additional help would be appreciated because at this point I'm merely adding anything I think would change the outcome of the collision, to no avail. http://forum.thegamecreators.com/?m=forum_view&t=17979&b=6
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 18th Oct 2011 20:38 Edited at: 18th Oct 2011 20:45
I used Sparkys for laser collision. For the actual model I created a textured cylinder exactly 1 unit long (diameter is sized to look right). Make sure it's semi-transarent and it doesn't have polygons at either end.

Raycast using Sparkys to find the hit point.

Find the distance to the hitpoint. Stretch the laser model by the distance to the hitpoint.

For a laser light effect at the end a simple plain with a lens flare type of texture on it (png/tga with alpha). Using Sparkys this can be automatically rotated to the polygon/ normal of the hit point.

This is of course for a laser beam, if you mean an arcade laser that flies through the air...that's different!!

www.illuminatedfx.com
For web design and graphic design services
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 29th Oct 2011 18:41 Edited at: 29th Oct 2011 19:11
Thanks Nick. Not what I'm looking for yet but when I do need it, I'll be back My game is 2d (with some 3d backgrounds)
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 9th Nov 2011 01:14
Unless I'm missing something completely obvious, I can't seem to get the collision I need. (still trying it) If anyone has any other thoughts on this, they would be much appreciated (followed by me getting on the floor and bowing in front of my computer screen chanting that "I'm not worthy, I'm not worthy!"). Would pixel perfect collision be a better choice after all?
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Nov 2011 07:00
I'm a bit confused on what you're trying to do. I didn't see lasers in either of those two videos. If you're talking about collision between the ship and all those stars, simply use circular collision.

Your signature has been erased by a mod please reduce it to no larger than 600 x 120.
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 9th Nov 2011 13:27
The laser was that giant beam of light and pain that the boss fired, and I already got circular collision. (in the second video, the laser is basically reversed and the boss is using it to charge at you) But my main point is that I'm trying to get "elliptical" collision or something that will work like that. Now, I can get collision for an ellipse (just some alterations to circular collision) but I need to be able to freely rotate (the most pressing problem) and position the ellipse which will serve as the collision. Right now I can only flatten or lengthen the ellipse but I need to be able to rotate it.

To be quick though, I need to rotate an ellipse (anywhere within 360 degrees) and still get it to collide with my player. (Dang, I might've made this whole thing sound too complicated, sorry)
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 9th Nov 2011 16:46
Hi there Goldsoul80. OK I'm going to do a shameless plug here and suggest you might want to look at my LineMap plugin. It offers simple line based collision that is quicker than pixel perfect and does calculations such as rotation for you. You can make procedurally generated collision lines as well as making them in a visual editor so you should be able to detect your laser using a procedurally generated line. You wouldn't be able to use circles though. Just another option to consider. Hope that helps!

Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 9th Nov 2011 19:20
Thanks Lucas I'll look in to it a bit later. (though I just downloaded it) Might this help me with rectangular collision as well? (for a different type of laser I wanna use later)

Still open to more ideas. (I'm not the only one who may benefit from these thoughts)
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 10th Nov 2011 02:13
Quote: "Might this help me with rectangular collision as well?"

Anything you can draw using straight lines can be used in line collision. Thanks for downloading . I hope you like it.

Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 15th Nov 2011 21:18 Edited at: 15th Nov 2011 21:19
I found this piece of code by Rich Dersheimer in this thread: http://forum.thegamecreators.com/?m=forum_view&t=183265&b=7

It makes an ellipse and sends it to an image, then a sprite so it can rotate, dont know if you can use it?



The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 16th Nov 2011 20:26
Thanks for trying but I need collision for a rotating ellipse. The best I can do with this is the sprite collision command. That will only return a square/rectangular collision box. Also, given how many bullets/lasers there may be on screen at any one time, using that command has been ineffective for me.
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 20th Nov 2011 23:05 Edited at: 22nd Nov 2011 21:35
I did a bit more searching and I just found this thing called a rotation matrix. (found it here: http://www.physicsforums.com/showthread.php?t=448289 )
Anybody know anything about these? I think this may be what I'm looking for. (of course I'll read it more when I get a bit more time)
(~couple days later~)
Do not understand this stuff...
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 2nd Dec 2011 17:14 Edited at: 2nd Dec 2011 17:18
Okay I (kinda) found a way to perform elliptical collision the way I need. Remember the link I pointed you to, telling you how I drew the ellipse using lines? http://forum.thegamecreators.com/?m=forum_view&t=17979&b=6 Well after I looked through some past codes I found on the site, I realized that I had a line/circle collision code.



For the life of me, I cannot remember where exactly (or who exactly) I got this code from but if you place that function here...



(the full code's in the link)
The inside of the ellipse won't provide collision however. (which isn't too important, I can work around that) Again, thank you guys for your help and I'll be back if I have another issue. (and hopefully others can benefit from this thread)
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 15th Dec 2011 15:23
Ugh i totally forgot about this one.

Anyways, here is my quick take on it. I provide collision detection, also inside the ellipse, with my konvex shape collision function.

Works awesome mostly, but likes to fail to notice collision when the ellipse is too small. I guess my function is not the best with integers, or maybe the too many bounding points are the problem... i have only used this with boxes before... i don't know right now, play around with it if you will.




-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 16th Dec 2011 15:11
I just checked it out and this is really awesome! Right now, I'm still just inputing what I found for the ellipse code in at most of my laser codes, though ,when I try to scale it, it scales improperly sometimes(my code). I don't really see any slow down with what I'm using but I like what I see with your code so I'd like to play with this code for a bit, disect it and what not. Thank you much!
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 16th Dec 2011 15:20 Edited at: 16th Dec 2011 15:24
Do as you wish, it's yours.

I just felt kinda bad i gave you notes, and left your there... and then you couldn't really get it to work, so i've been thinking about it too in the past weeks. To be honest with not much luck either, but yesterday i gave it an other go and just done it in 20 minutes!

EDIT:

As for the actual code, i wrote in the description of the collision function that you must identify point "from left to right"... well, this was really stupid from me, i meant counter-clockwise there.

-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
Goldsoul80
14
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 17th Dec 2011 02:26
Once again, thank you much for your help!

Login to post a reply

Server time is: 2026-07-10 03:09:41
Your offset time is: 2026-07-10 03:09:41