collisions and gravity

Blitz3D Forums/Blitz3D Beginners Area/collisions and gravity

ala_samodi(Posted 2004) [#1]
I have no clue?? every time i try to add collisions to this game it doesnt work no mader how many tries!!
<code>
Graphics3D 640,480,16,3
SetBuffer=BackBuffer()

Global campivot=CreateCube() ; create pivot for camera
Global camera=CreateCamera() ; create camera (!!!)

; ---------------------- THIS IS ALL JUST TO POPULATE THE WORLD WITH SOME RUBBISH ---------------

Global light=CreateLight()
Global player=CreateCube() ; create simple player
Global plane=CreatePlane() ; create simple floor
PositionEntity player,0,0,-10
MoveEntity player,0,1,0
; Create texture of size 256x256
tex=CreateTexture(256,256)

; Set buffer - texture buffer
SetBuffer TextureBuffer(tex)

; Clear texture buffer with background white color
For i=1 To 10
Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
Rect Rnd(0,256),Rnd(0,256),Rnd(0,256),Rnd(0,256)
Next

; Texture cube with texture
EntityTexture plane,tex
EntityTexture player,tex

; Set buffer - backbuffer
SetBuffer BackBuffer()

While Not KeyHit(1)
If KeyDown(200) Then
MoveEntity player,0,0,.2
End If
If KeyDown(203) TurnEntity player,0,1,0
If KeyDown(205) TurnEntity player,0,-1,0
If KeyDown(208) MoveEntity player,0,0,-.1
chasecam(camera,player,.02,8,3,0,0)

RenderWorld
Flip
Wend
End

Function chasecam(cam,ent,cspeed#,dist#,hite#,xrot#,tilt#)
TFormPoint 0,hite#,-dist#,ent,0
cx#=(TFormedX()-EntityX(cam))*cspeed#
cy#=(TFormedY()-EntityY(cam))*cspeed#
cz#=(TFormedZ()-EntityZ(cam))*cspeed#
TranslateEntity cam,cx,cy,cz
PointEntity cam,ent
RotateEntity cam,xrot#,EntityYaw(cam),tilt#
End Function
</code>
thats a no media crapy version of my game!!i'm giving credit to maker! and i also need a gravity

stupid code script thing!

I want the player to collide with campivot


puki(Posted 2004) [#2]
"mysticlore" you were probably on the right track - although you have taken the collision code out of the code that you have posted. Make sure you put UpdateWorld in front of Render World:

UpdateWorld; Perform collision checking
RenderWorld
Flip
Wend
End

UpdateWolrd animates all entities in your world and performs collision checking.

ps The code thing didn't work as you have used the '<' symbols - use the square bracket ones '['.

Good luck.

Edit:
In fact, type in 'UpdateWorld' into Blitz then click on the word with left mouse, then press F1 twice and Blitz will give you a collision help demo.


Ross C(Posted 2004) [#3]
mysticlore: Maybe you should read up on the collision command in the blitz help docs. To perform collisions, you need to first give the entities an entitytype.

;your code
Global light=CreateLight() 
Global player=CreateCube() ; create simple player 
Global plane=CreatePlane() ; create simple floor 
PositionEntity player,0,0,-10 
MoveEntity player,0,1,0
;my addition
EntityType player,1 ; give the player a different EntityType number from
EntityType campivot,2; the campivot entity


Then add somewhere before the main loop:

Collisions 1,2,2,2 ; first two parameters are the entities you want to perform collisions on.
                   ; Next two are the collision detection method and the collision responce.


Though i don't really see why you want the player to collide with the cam pivot :)


ala_samodi(Posted 2004) [#4]
Thank so very much both of you BUT i still need a gravity becuse now if i go up a ramp i would float?? im going to try to while not keyhit(1)
moveentity player,0,-1,0
somthing like that???

edit: ok that didnt work out it just made everything really sisnitive and freakout


Ross C(Posted 2004) [#5]
Yeah, something like that would do for simple gravity yeah :o)


ala_samodi(Posted 2004) [#6]
say i was on a mesh ramp and i was in the middle how could could i like not slide down but if i go in the air then i fall down


N(Posted 2004) [#7]
Example code of simple gravity-based collisions.

;; Set up collisions so that the player can walk up slopes while not sliding down them
Collisions PlayerID,WorldID,2,3

;; Main loop
Repeat

     ;; Gravity; VY = VelocityY
     VY# = VY# - .08
     
     ;; Jump
     If KeyHit(57) Then VY# = 2.5
     
     ;; Check for ground and or ceiling collision
     For i = 1 To CountCollisions(Player)
          ;; React accordingly
          If CollisionNY(Player,i) >= .1 Then
               VY# = 0
          ElseIf Abs(CollisionNY(Player,i)) >= .5 Then
               VY# = -Abs(VY#) * .64
          EndIf
     Next

     ;; Move the player
     TranslateEntity Player,0,VY#,0

     ;; Update world
     UpdateWorld

Until KeyHit(1)



ala_samodi(Posted 2004) [#8]
i got it i just needed to change it to collisions 1,2,2,3 and i stayed on the ramp