Bullet collides with enemy help

Blitz3D Forums/Blitz3D Beginners Area/Bullet collides with enemy help

CHALLENGER426(Posted 2008) [#1]
My first game is almost done...but i cannot figure out how to get the enemies to "die" when they are hit by the bullets. i know it has something to do with countcollisions or entitycollided, but i'm not sure how to get it to work. heres the code...


also can anyone show me how to use the mouse to move the sight to shoot the enemies...THANKS AGAIN


blackbag(Posted 2008) [#2]
I think you will probably need a COLLISIONS BULL,ENEMY line somewhere for starters. Currently it looks like you will only detect if a Enemy moves into a bullet, not the other way round.

Then you need to use ENTITYCOLLIDED to search your enemies to see if any have collided with a bullet (or you could search bullets for collisions with enemies). Store both the handle of the enemy and bullet and then deal with the results of the colision (remove bullet and enemy, create a explosion effect at the location of the impact etc etc etc etc).


Drak(Posted 2008) [#3]
One thing I noticed is you are loading the file "wcrate1.3ds" four times. Each of your debris entities a2 through a4, you can just use copyentity instead of loadentity and all of a's properties will be copied as well. All you will have to do is place the new entity.
a=LoadMesh("wcrate1.3ds")
ScaleMesh a,1,1,-1
FlipMesh a
FitMesh a,5,5,-5,5,5,5
PositionEntity a,300,-2,-30
EntityShininess a,-10
EntityType a,SCENE
RotateEntity a, -5,8,0

a2 = copyentity(a)
PositionEntity a2,280,-5,-30

a3 = copyentity(a)
PositionEntity a3,270,0,-20

a4 = copyentity(a)
PositionEntity a4,250,-6,-10


EDIT: Another thing I just noticed is you have your bullet's entityradius set to 0. You should set it to .1 because that's what your bullets are scaled to. A radius of 0 is of course, nothing, and that equals no collisions.


LedgerARC(Posted 2008) [#4]
all those things will definatly make death very much easier, without them there will be none, but the simple code to kill them would be:

if countcollisions (bullets) then
crash=collisionentity(bullets,1)
hideentity crash

this though must be put in a for...next loop with the same amount of numbers as bullets, and if there are any walls or anything they will get distroyes to. but by the looks of it there aren't. If there were then there would have to be a different collision type for the walls and the objects and it would look like this:

if entitycollided(the bullets,type_the thing you want to distroy) then
crash=collisionentity(bullets,1)
hideentity crash

this to would have to be in a for...next loop.

and for the thing about the mouse, I have a thing that I made myself, but you have to make sure that the graphics are higher than 720*720 (1024 by 768 is the best)
here it is:

;free move
HidePointer
movemouse graphicswidth()/2,graphicsheight()/2
turnentity camera,mousexspeed()/11,mouseyspeed()/11,0

This will make the mouse go in a loop divided by two into a full circle, take out the hidepointer command to see, and now all you have to do is rotate the camera to the position of the mouse

rotateentity camera1,mousey()/2,mousex()/2,0

hope this helped:)


Knight #51(Posted 2008) [#5]
Wuzup guys? This is my first time with my new acount so forgive me if i'm doing something wrong.

TIP: I've learned that instead of having to deal with COLLISIONS,COUNTCOLLISIONS and all of those other collision detection, you can just do a simple EntityDistance check e.g "If EntityDistance('whatever the player's coll_value is","whatever the bullets' coll_value is") < 1 "React to the collision"

As for aiming with the mouse, here is a simpler way:

HidePointer

MoveMouse GraphicsWidth()/2,GraphicsHeight()/2

TurnEntity camera,MouseXSpeed(),0,0
TurnEntity camera,0,MouseYSpeed(),0

NOTE: If this doesn't work try the following : inverting the MouseXSpeed() and/or MouseYSpeed(), or putting 'MoveMouse' command after the 'TurnEntity" commands.

(fingers crossed)