Jump to content
  • Advertisement
Sign in to follow this  
theoriginalrandomman

blitz 3d help

This topic is 3658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright. So, I learned b3d from a book called 3d game programming for teens. I suppose the book was a good start, but there's many things in there that they didn't address/do right. Gravity for one thing. Mouse control for another. Which brings me to my problem. I'm trying to put together a set of code for me to put in my games that calculates physics. It's supposed to be FPS style. Well, so far I have the basics together, such as: ground type player type prop type the player moves. I have not yet set up gravity and I can't figure out mouse control. I have a basic idea of how I'm going to set up gravity, but because the book didn't address how to use the mouse, I can't figure it out. Help? By the way, here is my code so far. You can't really use it unless you have a certain model. ; Gravity ;_______________ camdistance=10 Graphics3D 640,480 SetBuffer BackBuffer() ; Creating the types type_prop=1 type_ground=2 type_player=3 ; Create camera player=CreateCamera(pivot) PositionEntity player, 15,0,1 EntityType player, type_player ; Creating a light light=CreateLight() ; Creating a terrain terrain=CreateTerrain(512) EntityColor terrain, 125,136,32 PositionEntity terrain, -300,-1,-100 EntityType terrain,type_ground ; Creating the sky sky=CreateSphere(32) ScaleEntity sky, 100,100,100 EntityColor sky, 102,153,255 FlipMesh sky ; Creating a sphere sphere=LoadMesh("arwing.3DS") PositionEntity sphere, 15,0,6 EntityType sphere,type_prop ScaleEntity sphere ,0.5,0.5,0.5 Texture=CreateTexture(16,16): SetBuffer TextureBuffer(texture) ClsColor 12,35,36 Cls Color 123,256,256 Rect 0,0,8,8,1 Rect 8,8,8,8,1 ScaleTexture Texture,.2,.2 EntityTexture sphere,texture ; This following code makes our program run Collisions type_player,type_ground,2,2 Collisions type_ground,type_player,2,2 Collisions type_prop,type_ground,2,2 Collisions type_ground,type_prop,2,2 Collisions type_player,type_prop,2,2 Collisions type_prop,type_player,2,2 While Not KeyDown( 1 ) x#=0 y#=0 z#=0 If KeyDown( 30 )=True Then x#=-0.1 If KeyDown( 32 )=True Then x#=0.1 If KeyDown( 208 )=True Then y#=-0.1 If KeyDown( 57 )=True Then y#=0.1 If KeyDown( 31 )=True Then z#=-0.1 If KeyDown( 17 )=True Then z#=0.1 MoveEntity player,x#,y#,z# TranslateEntity sphere, 0,-.02,0 UpdateWorld RenderWorld Flip Wend End TL;DR: I can't figure out mouse control.

Share this post


Link to post
Share on other sites
Advertisement
Heres the the code i use to read the mouse using blitz3d.


Global screen_x_size = 1024
Global screen_y_size = 768
Global color_depth = 32
Global frame_rate = 60

Graphics3D screen_x_size,screen_y_size,color_depth

Global mouse_x#
Global mouse_y#
Global mouse_scale# = 0.2 ; this is used if the mouse movement is too fast

HidePointer ; hide cursor
ShowPointer ; show the cursor

function read_mouse()

mouse_x# = MouseX() - (screen_size_x / 2)
mouse_y# = MouseY() - (screen_size_y / 2)

mouse_x# = mouse_x# * mouse_scale#
mouse_y# = mouse_y# * mouse_scale#

;return cursor to screen centre
MoveMouse( screen_size_x / 2,screen_size_y / 2 )

end function

The variables ,mouse_x# , mouse_y# tell you how much the mouse was moved in the x and y directions.

I call read_mouse() at each pass of my code.


Gravity is really easy to code.

You need to check if your player is on the ground,

gravity# = 0
gravity_constant# = 0.1


If player in contact with the ground

gravity = 0

else

;player in the air
gravity# = gravity# + gravity_constant#

;update the players y world position by subtracting gravity from it.
player y position# = player y position# - gravity#

endif


The gravity# variable is vertical velocity and gravity_constant# is constant acceleration.


It's simply a case of subtracting the gravity# velocity from your players y position in order to fall the player back to the ground. Adding the gravity_constant# each time will accelerate the player towards the ground.



Also as a side note. There are a number of 3rd party physics wrappers available for blitz3d. These 3rd party libraries handle all the physics for you, but require a competent knowledge of blitz3d to use, so i wouldn't reccomend them for the beginner programmer.


KJM

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!