About my First project
Blitz3D Forums/Blitz3D Programming/About my First project
| ||
;Name of application AppTitle "My First Terrain And First animated Character" Print "Press F12 to exit" Print "After the wheels start moving" Print "Press Spacebar to move the car." Delay 2000 ;Initialise Graphics mode Graphics3D 800,600,16,1 SetBuffer BackBuffer() Const FPS=500 Const GRAVITY#=-0.01 ;Camera has to be set, so the scene is visible Camera=CreateCamera() ;CameraFogMode camera,1 ;CameraFogColor camera,1,150,150 PositionEntity camera,30,0,1,True ;Light The Scene, so that it doesn't look flat Light=CreateLight() RotateEntity Light,90,0,0 ;Create the "Terrain" Entity... terrain=LoadMesh("Land2.b3d") PositionEntity terrain,40,17,0 RotateEntity terrain,0,0,0 TranslateEntity terrain,30,-20,-.1 ;...and texture it Grass=LoadTexture("terrain-1.jpg") EntityTexture terrain,Grass ;Create a skybox using createsphere command sky=CreateSphere(16) ScaleMesh sky,800,800,800 sky_tex=LoadTexture("sky.bmp") EntityTexture sky,sky_tex EntityFX sky,1 FlipMesh sky FOG_RANGE=70 ;Create the "Box" entity and animate it box=LoadAnimMesh("model\BOX.B3D") ScaleEntity box,.1,.1,.1 PositionEntity box,0,-.9000,5 TranslateEntity box,30,-.70,-.70 EntityShininess box,1 SetAnimKey box,15,True,True,True AddAnimSeq(box,15) Animate box,1,2,0,100 ;Set Collision types fot the "collisions" command 1-player, 2-ground type_box=1 type_terrain=2 EntityType box,1 EntityType terrain,2 ;Adjust Radius of Sphere, that's used for Sphere-Polygon collisions box_radius#=1 EntityRadius box, box_radius ;Initialise Collisions between player and ground Collisions type_box,type_terrain,2,3 Collisions type_terrain,type_box,2,3 ;Dither scene, so that it does look good with 16 Bit Color-Depth ; Toggle dither enable value between true and false when F10 is pressed ;If KeyHit( 68 )=True Then enable=1-enable ;Dither enable ;other information about gravity speed#=0 x_vel#=0:prev_x#=EntityX( box ) y_vel#=0:prev_y#=EntityY( box ) z_vel#=0:prev_z#=EntityZ( box ) ;Main Loop While Not KeyHit(88) ;press F12 To Exit ;Press F11 to see the world in Wireframe mode If KeyHit(87)=True Then enable=1-enable WireFrame enable CameraFogRange camera,1,FOG_RANGE ;calculate box velocities cx#=EntityX( box ):x_vel=cx-prev_x:prev_x=cx cy#=EntityY( box ):y_vel=cy-prev_y:prev_y=cy cz#=EntityZ( box ):z_vel=cz-prev_z:prev_z=cz EntityParent(camera,box,1) ;Keyboard Input (cursor-keys) For moving the player around If KeyHit(57) If move_entities = True move_entities = False Else move_entities = True EndIf EndIf If move_entities = False ;all of your movement code If KeyDown(30) TurnEntity box,0,1,0 If KeyDown(32) TurnEntity box,0,-1,0 If KeyDown(31) MoveEntity box,0,0,-.01 If KeyDown(17) MoveEntity box,0,0,.01 If EntityCollided( box,terrain ) If KeyDown(17) speed=speed+.00 If speed>.0 speed=.0 Else If KeyDown(31) speed=speed-.02 If speed<-.5 speed=-.5 Else speed=speed*.9 EndIf MoveEntity box,0,0,speed TranslateEntity box,0,GRAVITY#-.01,0 Else TranslateEntity box,x_vel,y_vel+GRAVITY,z_vel EndIf EndIf TurnEntity sky,0,.02,0 ;Update the animation-Frames and Render the calculated scene, Flip Back- with Frontbuffer after that, so the new frame becomes visible UpdateWorld RenderWorld Flip Wend ;Free the Memory and end the program ClearWorld End |
| ||
Is there an other way to stop entities from moving? |
| ||
EDIT: removed |
| ||
Something like this in the main loop will work ... if keydown(57) repeat : until keydown( restart_key_scancode ) endif Stevie |
| ||
I've tried what you suggested Stevie G but when I press 57 it stops the entity witch is good. But crashes the program after I pressed it Anyway I tested my project again but on my big computer with ati 9200 graphics card it did the same thing and there was a slight difference with how the program ran for starters Entity shininess command shows the shininess well on my laptop but on my big computer it doesn't show at all is there a way to fix entity shininess or is it my ati cards settings I half to mess with? just curious :| |
| ||
Stevie G should have stated that restart_key_scancode was pseudocode for whatever key you wanted the player to press to restart the entities movement. Also, the method he showed would stop ALL program action, which usually isn't what you want Here's a better way: If keyHit(57) If move_entities = True move_entities = False Else move_entities = True EndIf EndIf If move_entities = True ;all of your movement code If KeyDown(30) TurnEntity box,0,1,0 If KeyDown(32) TurnEntity box,0,-1,0 If KeyDown(31) MoveEntity box,0,0,-.01 If KeyDown(17) MoveEntity box,0,0,.01 If EntityCollided( box,terrain ) If KeyDown(17) speed=speed+.00 If speed>.0 speed=.0 Else If KeyDown(31) speed=speed-.02 If speed<-.5 speed=-.5 Else speed=speed*.9 EndIf MoveEntity box,0,0,speed TranslateEntity box,0,GRAVITY#=-.01,0 Else TranslateEntity box,x_vel,y_vel+GRAVITY,z_vel EndIf EndIfBy the way, it's usually better to collect user input ONE TIME seperately from the rest of your movement code. Check out some of my code samples on my site for examples, if you haven't done so before. |
| ||
BTW, it appears that you have a mistake (the equal sign) in this section of code:TranslateEntity box,0,GRAVITY#=-.01,0Oh yeah, and if you want to know how to post code in the code format (which will also show indenting properly), read What are the forum codes?. |
| ||
Thank you WolRon yours code seem's to work perfect for me I change these lines a little to see if they give me a different effect and your version works better. But I changed the true and false commands like so. If KeyHit(57) If move_entities = True move_entities = False Else move_entities = True EndIf EndIf If move_entities = False after changing these lines. When I went to test it out it was running differently I would push 17 first and it move then press spacebar to stop it and press it again to release it But when I tried it your way it wouldn't let me move the entity at all unless I pressed the spacebar first then it would let me move :) P.S Thanks for showing me the forum I sometimes forget about the [] code line |
| ||
Also today I been reading the 3d tutorial on the forums here and been playing the simple version of a skybox using Createsphere (16,camera_pivot) command it's okay but when turning your entity left or right it show a black hole why is that? Is it me or is it just my ATI 9200 Card That can't seem to support entity shininess |
| ||
Seferey, the camera is Probbaly looking Through the Sphere , Try scaling it a bit larger. for example Scalemesh Skysphere,3,3,3 Createsphere (16,camera_pivot) is going to Rotate it with the camera , you dont want that. you should Create the Sphere normaly Skysphere=CreateSphere(16) Then texture it. make it full bright so light doesnt effect it Entityfx Skysphere,1 you might also want to change its order to its rendered behind other objects no matter its scale. EntityOrder Skysphere,10 Then, in the main program loop update its position with the camera Positionentity Skysphere,EntityX(camera),EntityY(camera),EntityZ(camera) Zmatrix |
| ||
If move_entities = True move_entities = False Else move_entities = True EndIf move_entities = Not(move_entities) |
| ||
Hi the sky sphere commands work but the problem is still there also is there another way to create entity shininess After the black hole part when my entity fall's off the terrain the entityshininess command turns on and actually shows it |
| ||
delete thread |
| ||
Your camera range is too short - or your sphere is too big. Simply make a sphere that is larger than the camera near distance and smaller than the camera far distance, set the entityorder so that it renders behind everything and remember to update its position so that it is centred on the cameras position at all times. |
| ||
I put the camera range to CameraRange Camera,1,8000 and it fixed the sphere problem now the last problem to fix is Entityshininess box,1 it loads up at start fine on my laptop but on my big computer with my Ati 9200 it loads up after I fall off the terrain. Why does this happen? Also I discovered that my Ati 9200 card seems to show entity shininess command. when I run My source code with the camerafogmode and camerafogcolor commands togethger it show my entity shiniess And one more thing. Is there a way to put boundries to prevent My entity from falling off the terrain? |
| ||
Is there a way to put boundries to prevent My entity from falling off the terrain? how do I create a quad |
| ||
add 4 invisible boxes or quads around your terrain and include them into your collisionroutine. |
| ||
[codebox] |
| ||
create a cube, resize it using fitmesh so that the borders are aligned with the terrain borders, then use flipmesh to invert it, set its entityalpha to 0 and include it in your collision routine. |
| ||
I fixed it but it seem's to not work anyway;Name of application AppTitle "My First Terrain And First animated Character" Print "Press F12 to exit" Print "Press F11 to see Wireframe Mode." Print "After the wheels start moving" Print "Press Spacebar to move the car." Delay 2000 ;Initialise Graphics mode Graphics3D 800,600,16,1 SetBuffer BackBuffer() ;Const FPS=500 Const GRAVITY#=-0.01 ;Camera has to be set, so the scene is visible Camera=CreateCamera() CameraRange Camera,1,8000 ;CameraFogMode camera,1 ;CameraFogColor camera,1,150,150 ;CameraFogColor camera,20,23,150 PositionEntity camera,30,0,1,True ;Light The Scene, so that it doesn't look flat Light=CreateLight() RotateEntity Light,90,0,0 ;Create the "Terrain" Entity... terrain=LoadMesh("Land\Land2.b3d") PositionEntity terrain,40,17,0 RotateEntity terrain,0,0,0 TranslateEntity terrain,30,-20,-.1 ;...and texture it Grass=LoadTexture("Land\terrain-1.jpg") EntityTexture terrain,Grass ;Create A Border Line Wall=CreateCube() FitMesh Wall,600,600,600,600,600,600 ;ScaleMesh Wall,600,600,600 EntityAlpha Wall,0 EntityOrder Wall,20 FlipMesh Wall ;Create a skybox using a model sphere Sky1=CreateSphere(32) ScaleMesh Sky1,5000,5000,5000 PositionEntity Sky1,30,-.9000,0 Sky=LoadTexture("Sky\sky.bmp") EntityTexture Sky1,Sky EntityFX Sky1,1 EntityOrder Sky1,20 FlipMesh Sky1 ;FOG_RANGE=400 ;Create the "Box" entity and animate it box=LoadAnimMesh("model\BOX.B3D") ScaleEntity box,.1,.1,.1 PositionEntity box,0,-.9000,5 TranslateEntity box,30,-.70,-.70 EntityShininess box,1 SetAnimKey box,15,True,True,True AddAnimSeq(box,15) Animate box,1,2,0,100 ;Set Collision types fot the "collisions" command 1-player, 2-ground 3-border type_box=1 type_terrain=2 type_Wall=3 EntityType box,1 EntityType terrain,2 EntityType Wall,3 ;Adjust Radius of Sphere, that's used for Sphere-Polygon collisions box_radius#=1 EntityRadius box,box_radius ;Initialise Collisions between player,ground and border Collisions type_box,type_terrain,2,3 Collisions type_terrain,type_box,2,3 Collisions type_Wall,type_terrain,2,1 Collisions type_terrain,type_Wall,2,1 ;Dither scene, so that it does look good with 16 Bit Color-Depth ; Toggle dither enable value between true and false when F10 is pressed If KeyHit( 68 )=True Then enable=1-enable Dither enable ;other information about gravity speed#=0 x_vel#=0:prev_x#=EntityX( box ) y_vel#=0:prev_y#=EntityY( box ) z_vel#=0:prev_z#=EntityZ( box ) ;Main Loop While Not KeyHit(88) ;press F12 To Exit ;Press F11 to see the world in Wireframe mode If KeyHit(87)=True Then enable=1-enable WireFrame enable ;CameraFogRange camera,1,FOG_RANGE ;calculate box velocities cx#=EntityX( box ):x_vel=cx-prev_x:prev_x=cx cy#=EntityY( box ):y_vel=cy-prev_y:prev_y=cy cz#=EntityZ( box ):z_vel=cz-prev_z:prev_z=cz EntityParent(camera,box,1) ;Keyboard Input (cursor-keys) For moving the player around If KeyHit(57) If move_entities = True move_entities = False Else move_entities = True EndIf EndIf If move_entities = False ;all of your movement code If KeyDown(30) TurnEntity box,0,1,0 If KeyDown(32) TurnEntity box,0,-1,0 If KeyDown(31) MoveEntity box,0,0,-.01 If KeyDown(17) MoveEntity box,0,0,.01 If EntityCollided( box,terrain) If KeyDown(17) speed=speed+.00 If speed>.0 speed=.0 Else If KeyDown(31) speed=speed-.02 If speed<-.5 speed=-.5 Else speed=speed*.9 EndIf MoveEntity box,0,0,speed TranslateEntity box,0,GRAVITY#-.01,0 Else TranslateEntity box,x_vel,y_vel+GRAVITY,z_vel EndIf EndIf TurnEntity Sky1,0,.02,0 PositionEntity Sky1,EntityX(camera),EntityY(camera),EntityZ(camera) ;Update the animation-Frames and Render the calculated scene, Flip Back- with Frontbuffer after that, so the new frame becomes visible UpdateWorld RenderWorld Flip Wend ;Free the Memory and end the program ClearWorld End |
| ||
I now got it to work by writing ;Create A Border Line Wall=CreateCube() ScaleMesh Wall,600,600,600 PositionMesh Wall,50,17,0 EntityAlpha Wall,0 EntityOrder Wall,20 FlipMesh Wall ;Set Collision types fot the "collisions" command 1-player, 2-ground 3-border type_box=1 type_terrain=2 type_Wall=2 EntityType box,1 EntityType terrain,2 EntityType Wall,2 Collisions type_box,type_terrain,2,3 Collisions type_terrain,type_box,2,3 Collisions type_Wall,type_terrain,2,3 Collisions type_terrain,type_Wall,2,3 right here Where it says ;Create A Border Line the fitmesh command doesn't seem to work But when I got rid of it and wrote ;Create A Border Line Wall=CreateCube() ScaleMesh Wall,600,600,600 PositionMesh Wall,50,17,0 EntityAlpha Wall,0 EntityOrder Wall,20 FlipMesh Wall it works correctly thanks :) |
| ||
You haven't set up collisions between the player (type_box) and the border (type_border), for some reason you have set up collision between the terrain and the border |
| ||
I'm currently using a pak explorer the latest and my question is. how do I load the content Inside the .pak file I made in Blitz3D? Just Curious :) |
| ||
I have a quick question about drawimage command not related to this project of mine I'm currently making a mouse pointer but my problem is I can't seem to get rid of the white square box around the mouse cursor I've already tried photoshop 7 with transparency and imageicon as well :( |
| ||
Try new threads for new questions. Also, you might find the Beginner Forum more helpful. |
| ||
thanks octothorpe I'll go look at the beginner forums |