The Daily Click ::. Forums ::. Klik Coding Help ::. Bullet collision
 

Post Reply  Post Oekaki 
 

Posted By Message

Aptennap



Registered
  4/23/2004
Points
  916
6th March, 2009 at 10:31:11 PM -

If I'm using : always set xvel("bullet") to xvel( "bullet" )+Cos(Angle( "bullet" ))*50 set xpos to xvel etc. for bullets, then how would I check for bullet overlapping? Cause if I just do if bullet is overlapping backdrop then the bullet might go over the backdrop because it skips so much space. I'm guessing I would need to use fastloops, it's for an online game (does that make a difference?).

EDIT : Also how could I do collision testing for a 360 movement (like GTA 1 and 2).

Edited by Aptennap

 
Oh sweet mary.

dndfreak



Registered
  1/11/2009
Points
  650
7th March, 2009 at 4:18:58 AM -

Im not sure about the first question but i have a method for the second one. I think there's a better way to do this but it still works.

I'm assuming you mean collides with front, side or back, right? I put however many objects you need under the player, then have collisions for each of them. For example, let's say you have four animations for death depending upon what side your guy was shot from. So take your guy (lets make him circular) and put four quarter-circles underneath. One faces front, one back, and the others left and right. Give each the same movement as the player so that they stay proportionate. Then have four collision statements with the bullets but instead of using the player object use the pie pieces. If they're killed from a shot to the back, play the appropriate animation, the same goes for the others.

I hope I helped you out here.

 
Vegeta? What does your mother say about my power level?

ITS OVER 9000!!!

Aptennap



Registered
  4/23/2004
Points
  916
7th March, 2009 at 11:09:17 AM -

Thanks, that helped .

 
Oh sweet mary.

Sketchy

Cornwall UK

Registered
  11/6/2004
Points
  2479

VIP Member
7th March, 2009 at 12:52:11 PM -

You can run a fastloop to move the bullet in smaller increments.
In the example below, the bullet checks for collisions every 5 pixels, but the bullet still moves at the right speed because the movement loop is repeated 10 times per frame.

+ always
-> start loop "move" 10 times

+ on loop "move"
-> set xpos("bullet") to xpos( "bullet" )+Cos(Angle( "bullet" ))*5
-> set ypos("bullet") to ypos( "bullet" )-Sin(Angle( "bullet" ))*5
-> set x to xpos
-> set y to ypos

+ on loop "move"
+ bullet overlapping
-> stop loop "move"
-> other stuff...

You could move the bullet in increments of a single pixel (replace "10" with "50", and "5" with "1"), but this would be inefficient.

Or just to use the MoveSafely extension.

As for detecting the relative angle of collision, read this thread: http://www.create-games.com/forum_post.asp?id=244612

 
n/a

Aptennap



Registered
  4/23/2004
Points
  916
7th March, 2009 at 1:18:36 PM -

Thanks. What if there are more than one bullet at a time, will this work then?

 
Oh sweet mary.

Sketchy

Cornwall UK

Registered
  11/6/2004
Points
  2479

VIP Member
7th March, 2009 at 1:36:11 PM -

yeah, just get rid of the "stop loop: move" action - you don't need it anyway.

 
n/a

Aptennap



Registered
  4/23/2004
Points
  916
7th March, 2009 at 1:47:48 PM -

Oke thanks! (word word)

 
Oh sweet mary.

tetsuya_shino



Registered
  8/12/2004
Points
  545
8th March, 2009 at 1:17:59 AM -

Greetings. While we are on the subject of bullets, I had a quick question. I want to shoot a bullet like object which will cause an event when it connects. The problem is that I only want it to hit one enemy. I know there is a trick if you are working with clones, but all my enemies have different file names. Any ideas? Thanks.

 
Family man living in Japan. - I do not expect or desire C&C unless otherwise noted. Thank you.

Assault Andy

Administrator
I make other people create vaporware

Registered
  7/29/2002
Points
  5683

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
8th March, 2009 at 1:35:19 AM -

Use the move safely 2 object. You can keep your normal shooting code and it can find if your bullets would have gone through walls, stopping them in the right place. There are example included which show you exactly how to use it.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

tetsuya_shino



Registered
  8/12/2004
Points
  545
8th March, 2009 at 1:41:33 AM -

er, I'm using tgf

 
Family man living in Japan. - I do not expect or desire C&C unless otherwise noted. Thank you.
   

Post Reply



 



Advertisement

Worth A Click