Need help with firing bullets B4 I go CRAZY!!!

Blitz3D Forums/Blitz3D Beginners Area/Need help with firing bullets B4 I go CRAZY!!!

W(Posted 2006) [#1]
I am really having some trouble getting my bullets to work correctly in my FPS, I mean they still don't move, and I keep getting errors saying that my bullet entity no longer exists when I know it should, I think I am going legally crazy. I have been working at this all day. I tried to understand Wolron's FPS Turorial, but I think I need it put in lamens terms or broken down for me pa pa pa please!!!!


jhocking(Posted 2006) [#2]
code plz


Baystep Productions(Posted 2006) [#3]
Possible problem....

You are updating your bullets with a FOR loop and you are requesting the variable after you have deleted it. Usualy you would have deleted it when it hits a target, but are still calling for it after the "Deleter x" part.


I find that using actual entities is a slow aproach to making bullets. Instead just use LinePick/CameraPick to instanly find the end location of the bullet. So in other words call....

pick=CameraPick(camera,GraphicsWidth()/2,GraphicsHeight()/2)

Your end locations will be found using PickedX(), PickedY(), and PickedZ(). Then use this to actualy place a bullet hole

hole=CopyEntity(bullethole,holes)
	PositionEntity hole,PickedX(),PickedY(),PickedZ(),True
	AlignToVector hole,-PickedNX(),-PickedNY(),-PickedNZ(),3
	MoveEntity hole,0,0,-0.05
	If CountChildren(holes)>200 Then FreeEntity GetChild(holes,1)

Where "holes" is a blank pivot and "bullethole" is a small sprite of a bullet hole image.


WolRon(Posted 2006) [#4]
Yes PCD GUY, but that method only works for instantaneous 'bullets'. For slower 'bullets' (such as a rocket), my 'bullet' code would be necessary.
Also, my bullet code can be adapted to work with real (or unreal) flight trajectories, such as when the forces of gravity and friction affect the projectile.


By the way "W", did you read the responses to your last question in this thread?: http://www.blitzbasic.com/Community/posts.php?topic=54979


Also, I decided to reformat some of the 'bullet code' on my website to seperate it into different parts. Now the section of the code that kills the badguy is seperate from the rest of the bullet stuff so that it isn't as confusing.

Take a look at it again and see if it makes more sense now.

Add code between UpdateWorld and RenderWorld to check if any collisions occured between the bullets and anything else. Kill a badguy if the bullet hit one.
For thisbullet = Each bullettype				;iterate through all of the bullets
  If CountCollisions(thisbullet\entityhandle) > 0		;check if bullet collided with something
    enemyhit = EntityCollided(thisbullet\entityhandle, 3)	;note which enemy (entity type 3) bullet collided with (if any)
    If enemyhit > 0 Then KillBadGuy(enemyhit)			;enemyhit contains entity handle of enemy that was hit
    FreeEntity thisbullet\entityhandle				;delete the bullet mesh
    Delete thisbullet						;delete the bullet
  EndIf
Next
And finally add this function after the end of the program to kill a badguy if he was struck with a bullet.
Function KillBadGuy(enemyhit)
  For thisbadguy.badguytype = Each badguytype			;iterate through all of the badguys
    If enemyhit = thisbadguy\entityhandle			;check if the enemy hit = this badguy
      If thisbadguy\state <> 5					;check if badguy is alive
        thisbadguy\state = 5 ;dead				;make him dead
        EntityType thisbadguy\entityhandle, 0			;turn off collisions for this badguy
        RotateEntity thisbadguy\entityhandle, 90, 0, 0		;make him horizontal
        TranslateEntity thisbadguy\entityhandle, 0, -.9, 0	;set him on the ground
        Exit							;exits the badguy For-Next loop (no need to check rest of badguys)
      EndIf
    EndIf
  Next
End Function



"W", if all else fails, then try posting for us some of the relevant code.


W(Posted 2006) [#5]
Thanks for the input guys the input is Very helpful! I do have a question though, PCD guy, The blank pivot is confusing....how did you set it's location for each bullethole???

-All input Appreciated!!


W(Posted 2006) [#6]
Im just confused as to what Im supposed to do with "holes", which is the blank pivot, can anyone help me out???


Sir Gak(Posted 2006) [#7]
I believe the PickedX(camera), PickedY(camera) and PickedZ(camera) give you coordinates for where to put the pivot, and hence the location of where to set the location for each bullethole.


W(Posted 2006) [#8]
Okkay I am trying to get ahold of this concept guys.

-This is what I got soo far, and it is still non responsive, can anyone tell my why or help me out at all??

;some code of mine ======================================
Function CheckWeapon()

pick = CameraPick(cam\model,GW,GH)


If MouseHit(1)
hole = CopyEntity(b\holes,holes)
PositionEntity holes,PickedX(),PickedY(),PickedZ(),True
PositionEntity hole,PickedX(),PickedY(),PickedZ(),True
AlignToVector hole,-PickedNX(),-PickedNY(),-PickedNZ(),3
MoveEntity hole,0,0,-0.05
EndIf

If CountChildren(holes) > 200 Then
FreeEntity GetChild(holes,1)
EndIf

End Function
;========================================================

In the initialization section I did this..

;=======================================
ScaleEntity b\holes,.05,.05,.05
Global holes = CreatePivot()

;=========================================

Oh GW and GH is the graphics width and height


WolRon(Posted 2006) [#9]
Well, just quickly looking at your code, I see that you are picking an entity at the lower right corner of the screen...
pick = CameraPick(cam\model,GW,GH)
I believe you meant to use:
pick = CameraPick(cam\model,GW/2,GH/2)



W(Posted 2006) [#10]
well my GW and GH variables were already divided by 2 previously sorry about that not posting that.

I just can't get the bullet hole picture technique to work.
Can you help me out here WolRon??


IPete2(Posted 2006) [#11]
W,

Just a few bits of friendly advice.

I would make the 'hole' a cube entity or something else you can definately see - ie with depth for debug purposes.

I m confused by the fact you have two entities holes and hole.
PositionEntity holes,PickedX(),PickedY(),PickedZ(),True

As you have two different names holes and hole - which is the hole you are trying to see?

Also write the co- ordinates of the camera and the holes to screen top left so you can see if they are about right.

Makbe try to make your life a little easier by placing the holes somewhere you know you can see them and we then know they are being created upon command (i.e. when you expect them to be).

IPete2.


W(Posted 2006) [#12]
I DID IT.............. OH my god I have bullets and shooting action, thanks 2 all


Sir Gak(Posted 2006) [#13]
Don't know if you want to fire at where the mouse cursor is, but if you are, consider the following:
pick = CameraPick(cam\model,MouseX(),MouseY())
This way, you can shoot at whatever you hover your mouse pointer over anywhere at the screen, not just dead-ahead.