question about collisions

Blitz3D Forums/Blitz3D Beginners Area/question about collisions

Rubiks14(Posted 2005) [#1]
is there any way to check like a certain area of a mesh with something, well for example like a fighting game if you have a weapon and it hits other person then they take damage. that should give you an idea of what i mean.
thanks, Rubiks14


Hujiklo(Posted 2005) [#2]
Using a bones animated mesh is the best bet. Then you can just check bounding boxes of each important bone for collisions. You'll have to use the 'child' commands in order to check the bones.


Rubiks14(Posted 2005) [#3]
ok thank you, the reason i ask is because i started messing around with my fps engine that i started workin on a long time ago and i am having problem with my camera running up the walls while i hold the jump button. i know why it does this(i'm checking collision with my whole level) but i dont know how to fix it. here is my code. i was thinking if i can't get anything else to work that i would put an invisible flat mesh that is not wider then the collision radius at the bottom of the player(pivot)

; * FPS sample.
; * Program code by Simon Harrison (si@...).
; * Gargoyle model by Adam Gore.

; Graphics values
Const width=640,height=480,depth=16								

; Collision type values
Const type_camera=1 
Const type_scenery=3,type_ladders=4	; Destination

; Camera position, angle values
Global cam_x#,cam_z#,cam_pitch#,cam_yaw#						; Current
Global dest_cam_x#,dest_cam_z#,dest_cam_pitch#,dest_cam_yaw#	; Destination
Global jumped = 0
Global PGrav# = 0.0
Global Grav# = 0.2

; Set display mode
Graphics3D width,height,depth
SetBuffer BackBuffer()

; Set up camera
Global camera=CreateCamera()					
CameraRange camera,1,600
EntityRadius camera,7.5
EntityType camera,type_camera
PositionEntity camera,10,10,10

; Set up lights
AmbientLight 191,191,191						
Global light=CreateLight()
LightColor light,31,31,31
RotateEntity light,45,0,0

; Load level
Global level=LoadMesh("interior.x")	
ScaleEntity level,100,100,100
EntityType level,type_scenery
EntityPickMode level,2

; Load ladders collision mesh
Global ladders=LoadMesh("ladders.x")
ScaleEntity ladders,100,100,100
EntityType ladders,type_ladders
EntityAlpha ladders,0

; Initialise collisions
Collisions type_camera,type_scenery,2,3
Collisions type_camera,type_ladders,2,2


; Main loop
; ---------

Global old_time=MilliSecs()
While Not KeyHit(1)

PGrav# = PGrav# - Grav#

TranslateEntity camera,0,PGrav#,0

If EntityCollided(camera,type_scenery)
	PGrav = 0.0
	jumped = 0
EndIf

	UpdateGame()
	UpdateWorld
	RenderWorld
	
	; FPS
	frames=frames+1
	If MilliSecs()-render_time=>1000 Then fps=frames : frames=0 : render_time=MilliSecs()	
	Text 0,0,fps
	
	Flip
	
Wend
End


; --------------------
; Update game function
; --------------------

Function UpdateGame()

	GameInput()
	
End Function


; -------------------
; Game input function
; -------------------

Function GameInput()

	; Mouse look
	; ----------

	; Mouse x and y speed
	mxs=MouseXSpeed()
	mys=MouseYSpeed()

	; Destination camera angle x and y values
	dest_cam_yaw#=dest_cam_yaw#-mxs
	dest_cam_pitch#=dest_cam_pitch#+mys

	; Current camera angle x and y values
	cam_yaw=cam_yaw+((dest_cam_yaw-cam_yaw)/5)
	cam_pitch=cam_pitch+((dest_cam_pitch-cam_pitch)/5)
	
	RotateEntity camera,cam_pitch#,cam_yaw#,0
	
	; Rest mouse position to centre of screen
	MoveMouse width/2,height/2
	

	; Camera move
	; -----------
	
	; Forward/backwards - destination camera move z values
	If KeyDown(17)=True Or MouseDown(2)=True Then dest_cam_z=1
	If KeyDown(31)=True Then dest_cam_z#=-1

	; Strafe - destination camera move x values
	If KeyDown(32)=True Then dest_cam_x=1
	If KeyDown(30)=True Then dest_cam_x=-1
	
	If KeyDown(57) And jumped = 0
		PGrav# = 3.0
		jumped = 1
		FlushKeys
	EndIf
	
	; Current camera move x and z values
	cam_z=cam_z+((dest_cam_z-cam_z)/5)
	cam_x=cam_x+((dest_cam_x-cam_x)/5)

	; Move camera
	MoveEntity camera,cam_x,0,cam_z
	dest_cam_x=0 : dest_cam_z=0
	
	; Climb ladders
	If EntityCollided(camera,type_ladders)<>0 Then PGrav# = PGrav# + .25
End Function


note: most of this code isn't mine it is the fps demo that comes with blitz but my engine isn't this code i was just testing my stuff in an actual level(instead of terrain) so i used that


Hujiklo(Posted 2005) [#4]
A quick look - I'd say you should put the 'entitycollided (scenery)' part before the translate command.I'm too hung up in my own blitz problems right now to look much deeper..maybe later.


Rubiks14(Posted 2005) [#5]
i changed them up and it didn't do anything, but i know why i'm running up the walls(because i'm checking the collision for the player with the WHOLE level), i just don't know how to fix it. does anybody else have an idea that will stop that from happening(and please put it in code because i can understand better if i read the code), and i dont want to have to make the wall and the floor different collisions unless there is any easy way to do that


Stevie G(Posted 2005) [#6]
Instead of this ..

If EntityCollided(camera,type_scenery)
	PGrav = 0.0
	jumped = 0
EndIf


Do something like this ...

for c = 1 to countcollisions( camera )
 if collisionny( camera , c ) > 0    
   PGrav = 0
   Jumped = 0
 endif
next


This basically means that gravity and jump will only be reset if you collide with something below you.

Hope this helps.
Stevie


Rubiks14(Posted 2005) [#7]
oh thank u so much. it works yay(i've had problems with this for a long long time.

EDIT: oh it was to good to be true, i can't go up ramps now or the ladder(the level is the level from the fps example by si that comes with blitz3d so u can see what i mean

edit again: nevermind i fixed it


Rubiks14(Posted 2005) [#8]
now there is just one more thing (hopefully). if my camera is looking above the straight position then i kinda hop up and down. do you think you can fix that


Stevie G(Posted 2005) [#9]
Not sure what you mean? Post you're code so I can see a working example.


Hujiklo(Posted 2005) [#10]
You know - I think there is better and more straight forward fps code in the code archives on this website. I think you should try a few different ones before you settle for one particular method. I had similar problems when I first started until I nailed down some code that did things more along the lines so how I imagined.
Sometimes you just end up with a scrappy piece of code that works because you made it work out of sheer grief in the end - but it can be real ugly!


Rubiks14(Posted 2005) [#11]
ok i think i'll do that. i've used like 2 combined right now but i'll have a look and see what else i can dig up.
Not sure what you mean? Post you're code so I can see a working example.

ok say i am looking straight like i just got in the game, now if i move the camera up above(lets call it 50%) then it will make my guy literally hop up and down, it's just a small amount but it is enough to drive a man crazy. I know that it is my mouse look that is causing it because i switched up how it moved and it didn't do it anymore. it's just that it is not very smooth. so i wanted to see if that code up in one previous post could be edited to work or if you could give me another way to do the camera movement(i'm at work so i can't post code).

EDIT: i got it working YAY!!!!!. now i can move on to something else, but first i am rewriting code so it not so messy.