thrid person game
Blitz3D Forums/Blitz3D Beginners Area/thrid person game
| ||
Hi i have make the basics for my game and still working on it but am having a problem wit gravity in it cause the only one i know is where you put in the main loop 'moveentity player,0,-.1,0 but that does not give me what i need i need the proper gravity that you guys make so that you can only jump so high and can jump again till on the ground again. please help me:( |
| ||
Here's an example: ;An Example of Gravity: Graphics3D 640,480,16,1 Collisions 1,2,2,2 Cam=CreateCamera() EntityType cam,1 PositionEntity cam,0,9,0 CameraClsColor cam,0,255,255 ground=CreateCube() ScaleEntity ground,5,1,5 EntityType ground,2 While Not KeyHit(1) If Not EntityCollided(cam,2) TranslateEntity cam,0,-0.1,0 EndIf UpdateWorld RenderWorld Flip Wend End -me |
| ||
Er, that's not gravity at all! That's moving an entity downwards at a constant rate and then doing absolutely nothing when it hits the ground!Graphics3D 640,480,16 Global Gravity# = -0.05 Global YSpeed# = 0 Collisions 1,2,2,2 Cam=CreateCamera() Global ball = CreateSphere() light = CreateLight() PositionEntity ball,0,10,0 EntityType ball,1 PositionEntity cam,0,10,-25 CameraClsColor cam,0,255,255 ground=CreatePlane() EntityType ground,2 While Not KeyHit(1) UpdateGravity() ;TranslateEntity ball,0,-0.1,0 UpdateWorld If CountCollisions(ball) ySpeed = 0-ySpeed EndIf RenderWorld Flip Wend End Function UpdateGravity() Yspeed = YSpeed + Gravity TranslateEntity Ball,0,yspeed,0 End Function |
| ||
Er, that's not gravity at all! That's moving an entity downwards at a constant rate and then doing absolutely nothing when it hits the ground! Um, I agree with you about the constant thing but who said that when something hits the ground it has to bounce? |
| ||
Um, I agree with you about the constant thing but who said that when something hits the ground it has to bounce? Any object falling from a great height and hitting the ground will bounce to some extent (or splat). |
| ||
You are wrong. A lead ball the size of a tennis ball will hit the ground with such a force it will sink at least 3-6 feet. You can't make such generalizations. |
| ||
You are wrong. A lead ball the size of a tennis ball will hit the ground with such a force it will sink at least 3-6 feet. You can't make such generalizations. I've given him the code he asked for. Why must everything always be <snip> challenged around here???What *is* it with some people?? |
| ||
He may have been looking for a code snippet where the object stops when colliding with the ground. That's all I'm trying to say. So your code without bounce would look like: Graphics3D 640,480,16 Global Gravity# = -0.05 Global YSpeed# = 0 Collisions 1,2,2,2 Cam=CreateCamera() Global ball = CreateSphere() light = CreateLight() PositionEntity ball,0,10,0 EntityType ball,1 PositionEntity cam,0,10,-25 CameraClsColor cam,0,255,255 ground=CreatePlane() EntityType ground,2 While Not KeyHit(1) UpdateGravity() ;TranslateEntity ball,0,-0.1,0 UpdateWorld If CountCollisions(ball) ySpeed = 0 EndIf RenderWorld Flip Wend End Function UpdateGravity() Yspeed = YSpeed + Gravity TranslateEntity Ball,0,yspeed,0 End Function |
| ||
"Er, that's not gravity at all! That's moving an entity downwards at a constant rate and then doing absolutely nothing when it hits the ground!" So? It works perfectly fine for me. -me |
| ||
So? It works perfectly fine for me. So if you jump up in the air, do you float back to earth at a constant speed? |
| ||
Yes... -me |
| ||
Thanks guys |
| ||
Noooooooooooooooooooooooooooooooooooo! I cant get it to work the way i wanted. |
| ||
I made an improvment on that code: Graphics3D 640,480,16 Global Gravity# = -0.05 / 1 Global YSpeed# = 0 Collisions 1,2,2,2 Cam=CreateCamera() Global ball = CreateSphere() light = CreateLight() PositionEntity ball,0,30,0 EntityType ball,1 PositionEntity cam,0,10,-25 CameraClsColor cam,0,255,255 ground=CreatePlane() EntityType ground,2 While Not KeyHit(1) UpdateGravity() ;TranslateEntity ball,0,-0.1,0 UpdateWorld If CountCollisions(ball) ySpeed = 0 EndIf If EntityCollided(ball,2) Yspeed = 1.5 TranslateEntity ball,0,Yspeed,0 gravity = Gravity - 0.01 / Yspeed EndIf RenderWorld Flip Wend End Function UpdateGravity() Yspeed = YSpeed + Gravity TranslateEntity Ball,0,yspeed,0 End Function Goober, why don't you look in the Code Archives, they might have something in there. -me |
| ||
Gravity is a constant force but it`s results are effected my inrertia ,, so jumping up and formarrd will give a curving jump ,, also any object falling in a gravitational feild well accelarete to a terminal velocity. If ou drop a cannonball onto a surface it WILL bounce ,, it`s all dependant on how much energey the sufrace absorbs Bropping a large steel ball bearing the size of a cannnon ball onto a steel slab , and the ball will bounce quite high actually ,,, i have done this in the steel works i used to be employed at !! droping it into sand and as sand absorbs most of it`s kenetic energy it bounces verry little (although not easlt vivible the bounce is still there) As for people .. they can bounce quite spectacularly too ,, i once saw a video of a failed parachute landing onto grass and the guy bounced about 20 feet back ito the air and eventually came to rest ontop of a truck. The only way to get realistic physics is to model real physics,,, I suggest a book on newtonian physics to help here |
| ||
well i looked in the code area but cant find what i need cause i need player gravity so when space is pressed the player will jump but i do not know how to do that. |
| ||
Well, create a variable for jump_force and one for gravity. Set these to appropriate values. Then when the player presses spacebar, you should set a flag saying a jump is in progress. Have a function to update the jump. Basically you should be multipling the jump_force variable by the gravity (eg. gravity=0.001) and checking if the result is near zero, then change jump_force to a - minus number, and always check collisions. This should do the trick. It's not 100% full proof. It doesn't check to see if the player walks off anything, but the function should handle this. If you walk off something, then set the jump_flag to 1 with a jump force of 0 and that should do the trick. Hope this helps :) Graphics3D 800,600 SetBuffer BackBuffer() Global camera=CreateCamera() Global light=CreateLight() Global player=CreateCone() EntityType player,1 EntityColor player,50,70,255 PositionEntity player,0,0.5,0 PositionEntity camera,0,2,-6 Global tex=CreateTexture(64,64,1+8) SetBuffer TextureBuffer(tex) For loop=0 To 1000 Color Rnd(0,255),Rnd(0,255),Rnd(0,255) Rect Int(Rnd(0,63)),Int(Rnd(0,63)),1,1 Next Color 255,255,255 SetBuffer BackBuffer() Global plane=CreatePlane() EntityType plane,2 EntityColor plane,200,100,120 EntityTexture plane,tex Collisions 1,2,2,3; set up collisions between the ground and the player Global jump_force# Global jump_flag=0; set jump flag to 'no jump' Global gravity#=0.8; set gravity value While Not KeyHit(1) If KeyHit(57) And jump_flag=0 Then; if user presses spacebar jump_flag=1; set jump flag to 'jump' jump_force=1.3; set jumping force. make larger for higher jump End If If jump_flag=1 Then; if jump flag set then 'jump' update_jump() End If update_camera() UpdateWorld RenderWorld Text 0,0,"gravity="+gravity+" jump_force="+jump_force Flip Wend End Function update_camera() RotateEntity camera,EntityPitch(player),EntityYaw(player),EntityRoll(player); make the camera equal to the rotations of the camera PositionEntity camera,EntityX(player),EntityY(camera),EntityZ(player); position the camera at the x and z pos of the player MoveEntity camera,0,0,-7; move the camera back from the player by 7 units End Function Function update_jump() jump_force=jump_force*gravity; apply gravity to the jumping force MoveEntity player,0,jump_force,0; move the player If jump_force>0 And jump_force<0.05 Then; when players upward speed reaches alomost zero, reverse it ; make smaller to keep player in the air for longer jump_force=jump_force*-1; reverse the jumping force gravity=gravity+(2*(1-gravity)); turn gravity around End If If jump_force<-0.5 Then jump_force=-0.5; stop the player from falling to quick If EntityCollided(player,2) Then; if the player has collided with the ground jump_force=0; reset the jumping force jump_flag=0; reset jump flag back to zero (not jumping) gravity=gravity-(2*(gravity-1)); reset gravity End If End Function |
| ||
Thanks for the help. I can now continue my game for now. |
| ||
Just one more question, i allread have an update camera in it so the program wont run with it in but wont run without it. what has gone wrong if you need my source just ask. |
| ||
yeah, your source would be helpful plz :) |
| ||
Ok here is my code, I added the gravity but one little problem when you jump forward and hit something like a wall then you float in the air and if you jump again you fly to the cieling: ;SET UP GRAPHICS Graphics3D 640,480 SetBuffer BackBuffer() ;create camera camera=CreateCamera() EntityType camera,1 CameraRange camera,0.1,10000 ;LOAD EQUIPTMENT level=LoadMesh("level1.b3d") PositionEntity level,0,-1,0 ;ScaleEntity level,.01,.01,.01 EntityType level,2 ;collisions Collisions 1,2,2,3 campivot=CreatePivot() Global player=CreateCone() EntityParent campivot,player PositionEntity campivot,0,0,-7 EntityType player,1 Global jump_force# Global jump_flag=0; set jump flag to 'no jump' Global gravity#=0.8; set gravity value While Not KeyHit(1) ;MoveEntity player,0,-.1,0 If KeyDown(17) Then MoveEntity player,0,0,0.2 If KeyDown(31) Then MoveEntity player,0,0,-0.2 If KeyDown(30) Then TurnEntity player,0,2,0 If KeyDown(32) Then TurnEntity player,0,-2,0 If KeyHit(57) And jump_flag=0 Then; if user presses spacebar jump_flag=1; set jump flag to 'jump' jump_force=1.3; set jumping force. make larger for higher jump End If If jump_flag=1 Then; if jump flag set then 'jump' update_jump() End If Gosub updatecamera UpdateWorld RenderWorld Flip Wend End .updatecamera PointEntity camera,campivot MoveEntity camera,0,0,EntityDistance(camera,campivot)/10 PointEntity camera,player RotateEntity camera,EntityPitch(player),EntityYaw(player),EntityRoll(player); make the camera equal to the rotations of the camera PositionEntity camera,EntityX(player),EntityY(camera),EntityZ(player); position the camera at the x and z pos of the player MoveEntity camera,0,0,-7; move the camera back from the player by 7 units Return Function update_jump() jump_force=jump_force*gravity; apply gravity to the jumping force MoveEntity player,0,jump_force,0; move the player If jump_force>0 And jump_force<0.05 Then; when players upward speed reaches alomost zero, reverse it ; make smaller to keep player in the air for longer jump_force=jump_force*-1; reverse the jumping force gravity=gravity+(2*(1-gravity)); turn gravity around End If If jump_force<-0.5 Then jump_force=-0.5; stop the player from falling to quick If EntityCollided(player,2) Then; if the player has collided with the ground jump_force=0; reset the jumping force jump_flag=0; reset jump flag back to zero (not jumping) gravity=gravity-(2*(gravity-1)); reset gravity End If End Function please help me. |
| ||
It's because your whole level has the same collision type number. So if you jump against the wall, the function takes that as being the collision it's looking for. Another thing. Because i'm using a function, you really should make all of your variables global. Just incase they get mixed up with the ones used in the function. Mmmm. What you could do to solve your problem is when a collision is dected in the function, do a linepick straight down (see the linepick command). Then get the distance, and if it's very small, say 0.5 or less then stop the jump, but if it's not then continue to make the player fall. |
| ||
??? |
| ||
check the collisionnx and collisionnz during jumping and if it's a certain value ie >abs(0.9) apply gravity or kill the upward movement. You should also set any forward motion to 0 or you could get a sticking problem. |
| ||
'???' doesn't help us. Tell us which part you don't understand and why. Do as Ross says. Set the collision type of the wall to something else (which would probably require seperate meshes) or make your code use the linepick command and force the player down. |
| ||
????????????? |
| ||
Are you being childish? |
| ||
I just dont understand about what to do like is it allright to use cartography shop to make the levels the separate each part and then set the collision if so how? And i dont know how to do that linepick code thing. |
| ||
isn't linepick described in the command reference? |
| ||
yea but i does not help because it tell you about it but not how to use it. |
| ||
first you have to set the entitypickmode of the level mesh to polygonal. then you can make a linepick from the playerposition (eg. x,y,z) to somewhere below it. p=linepick(x#,y#,z#,0,-100,0,.1) if p<>0 py#=pickedy() grounddistance#=y#-py# endif |
| ||
As explained in the docs... |
| ||
Ok guys i tryed the linepick code i could not get it to work so i tryed with two seperate meshes but now i can only jump once. |
| ||
Explain better what you mean by only jumping once, or show your code again. |
| ||
ok here is my code: ;SET UP GRAPHICS Graphics3D 640,480 SetBuffer BackBuffer() ;create camera Global camera=CreateCamera() EntityType camera,1 CameraRange camera,0.1,10000 ;LOAD EQUIPTMENT level=LoadMesh("floor.b3d") PositionEntity level,0,-1,0 ;ScaleEntity level,.01,.01,.01 EntityType level,2 EntityPickMode level,2 wall=LoadMesh("walls.b3d") PositionEntity wall,0,-1,0 EntityType level,3 EntityPickMode level,3 ;collisions Collisions 1,2,2,3 Collisions 1,3,2,3 campivot=CreatePivot() Global player=CreateCone() EntityParent campivot,player PositionEntity campivot,0,0,-7 EntityType player,1 Global jump_force# Global jump_flag=0; set jump flag to 'no jump' Global gravity#=0.8; set gravity value While Not KeyHit(1) ;MoveEntity player,0,-.1,0 If KeyDown(17) Then MoveEntity player,0,0,0.2 If KeyDown(31) Then MoveEntity player,0,0,-0.2 If KeyDown(30) Then TurnEntity player,0,2,0 If KeyDown(32) Then TurnEntity player,0,-2,0 If KeyHit(57) And jump_flag=0 Then; if user presses spacebar jump_flag=1; set jump flag to 'jump' jump_force=1.3; set jumping force. make larger for higher jump End If If jump_flag=1 Then; if jump flag set then 'jump' update_jump() End If Gosub updatecamera UpdateWorld RenderWorld Flip Wend End .updatecamera PointEntity camera,campivot MoveEntity camera,0,0,EntityDistance(camera,campivot)/10 PointEntity camera,player RotateEntity camera,EntityPitch(player),EntityYaw(player),EntityRoll(player); make the camera equal to the rotations of the camera PositionEntity camera,EntityX(player),EntityY(camera),EntityZ(player); position the camera at the x and z pos of the player MoveEntity camera,0,0,-7; move the camera back from the player by 7 units Return Function update_jump() jump_force=jump_force*gravity; apply gravity to the jumping force MoveEntity player,0,jump_force,0; move the player If jump_force>0 And jump_force<0.05 Then; when players upward speed reaches alomost zero, reverse it ; make smaller to keep player in the air for longer jump_force=jump_force*-1; reverse the jumping force gravity=gravity+(2*(1-gravity)); turn gravity around End If If jump_force<-0.5 Then jump_force=-0.5; stop the player from falling to quick If EntityCollided(player,2) Then; if the player has collided with the ground jump_force=0; reset the jumping force jump_flag=0; reset jump flag back to zero (not jumping) gravity=gravity-(2*(gravity-1)); reset gravity End If End Function please reply soon. |
| ||
Help! please! |
| ||
"Goober" - were you intially wanting to go into a "gravity" issue in the first place? When I first saw your post, you simply asked "i need the proper gravity that you guys make so that you can only jump so high and can jump again till on the ground again. please help me". I thought you were using the word "gravity" as a general term and that it was more of a "jumping" question. However, by then the "gravity" argument had kicked off. I just assumed (and I may have been wrong) that you just wanted to know how to make the player jump - set a flag to show jumping, thus stopping you from jumping again - jump to a certain height - drop to the ground - reset the jumping flag, to enable you to jump again when you liked. That's purely how I interpreted your origianl question. Having been bombarded with "gravity" issues - does the code now (regardless of gravity) do what you initially intended (I accept my interpretation of what you originally asked may be wrong)? |
| ||
well if you mean the gravity when i said hat you could jump once and only once well no cause i want to ba able to jump more that once in the game just i dont want it to jump again when i the air. |
| ||
"Goober" - you misunderstood me, it's probaly the way I wrote it. However, the answer you have just posted is the question I asked. Basically, you asked a simple question and I think/assume it got interpreted wrong (but I'm still not sure if I am right or wrong here - I just get the impression I am). Did you intially intend to go into "jump force"/"gravity"? Is it important to your game? Has the whole thing become too complicated? |
| ||
Hey goober. Check out some code i made on the line pick code. It's nothing much, but gives the idea of how it works :) http://www.blitzbasic.com/Community/posts.php?topic=27837 |
| ||
Ok puki well i'm not that good at understanding things much more questions than the other things so if i explain what i'm trying to do here in my project might you understand what i'm needing help with. to your questions: Q.Did you intially intend to go into "jump force"/"gravity"? A.well i dont actually know weather these are what i need cause i'm trying to get the player in the third person view to jump at the users command for example in a basket ball game when you are going to shoot you might want to jump to get a better shot or if there is a gap between to floors you can make the player jmp across. I hope this answers this question? Q2.Is it important to your game? A2.yes it is important in my game because it is based in demon scenes and it will involve jumping accross gaps and such. Q3.Has the whole thing become too complicated? yes!?!? Ross C i took a look at the code and tested it but still nothing sinking into my big empty head. |
| ||
"Goober" - good return post! Now everyone knows what you are doing - there could be a use for "jump force"/"gravity" and now everyone knows you are finding it complicated - I assumed so because of your "???" posts. I'm away from my computer at the moment (I'm stuffing my face) - I'm not the person to help you - however, I'll post back later maybe in an hour (to describe your problem to you). "Ross C" (and others) may spot your post too - he's more of an expert. |
| ||
"Goober" - You may want to work on 2 separate copies of your code - one can be simple - the other have all the "physics" that you have acquired in it. If you haven't already got an old copy of your code or a spare on - make a copy your current code and strip all the "physics" out that you have added since your initial post (DON'T DELETE THE CURRENT COPY THOUGH - the one with "Jump Force"/"Gravity"). In a nutshell, you need a copy of your original code prior to having added the "physics" stuff in. Your game appears to be basket-ball like (in a jumping sense), with jumping between gaps. "Goober" - Explain the gaps to me. Is the player going to be jumping up and landing on ledges at different heights? Or, are the gaps all at the same level, ie. floor level (is the player, in a way, jumping from ledge to ledge at the same height level or different heights)? |
| ||
Well, what the Line Pick command does, is basically send a line in the direction you specify. Then you can check where abouts the line stopped using PickedY() PickedX() and PickedZ(). So, if your player is jumping, you would use the line pick command to send an invisible line downwards, and find the y co-ord the line stops at (in overwards, find the position the line collided with the floor) Now, then after each time you used LinePick, you would use PickedY(). Now, you would compare the players position against the value returned from PickedY() LinePick ( EntityX(cube),EntityY(cube),EntityZ(cube),0,-5,0) This piece of code will send a line downwards. LinePick [start x pos], [start y pos], [start x pos] The first three values in the LinePick command state where the line will start from. So ideally, this will be your players position, as that is the position you want to test for height. Now the next three values in the LinePick command state what direction the line will travel in. LinePick ( EntityX(player),EntityY(player),EntityZ(player) ,0,-5,0) In this example the first of the ,0,-5,0 bit. The first value is the distance in the x direction the line will travel in. I have 0 as i only want the line to travel downwards, along the y axis. The next value of -5, means i want the line to travel down -5 units on the y axis. Only use a small value for the distance, don't use like 1000 or something. The next value is the distance along the z axis you want the line to travel. Again, i put 0 as i only want the line to travel downwards. Ok so you use the LinePick command. LinePick ( EntityX(player),EntityY(player),EntityZ(player) ,0,-5,0) Now after that, use the PickedY() command ground=PickedY() This will put the y co-ord the line stopped at. Should return zero if the line didn't collide with anything. Now, if you compare the y location of your model with the PickedY() value, and there are pretty much the same (the players y co-ord should be greater of course, but not by much) and there has been a collision detected between your player and the level, you can assume that he is standing on the ground and disable any gravity applied on him and set the jump flag to NOT jumping. If the difference between PickedY() and the players Y co-ords are a bit different and a collision has been detected, then you can assume he has jumped into a wall, or jump and hit the roof, so keep appling gravity to him. Think that about covers everything. But see when you are compare the y location against PickedY(), make sure you use the y co-ord of the player-half his height. This is because, usually the players centre of rotation will be in the middle, and you don't want the location of the waist now do you ? :) [EDIT] Left out an important thing. The level MUST be pickable, meaning you'll have to use: EntityPickMode level,2 the ,2 part makes it's polygons pickable, which is very important! [/EDIT] |
| ||
"Goober" that's what you call a good post from "Ross C" - nice one Ross! |
| ||
Np ^_^ |
| ||
"Goober" - You haven't posted back yet. So I'll start typing my explanation for the "Physics" bit - and post it (hopefully within half an hour). Don't expect me to code it - I'm just going to explain why you may need it/how to use it so you can work out if you do or don't. It really depends on what you want your game to do - the "physics" bit just makes your game "feel" better - you don't technically need it and you can always add it later. |
| ||
"Goober" - I'm not the right person to help you, and I accept the following is a bit crude - but it may help you think about your game and what it is going to do: I'm assuming that this all may lead to you asking a secondary question at some point in relation to "scoring a goal". Your game could use the "Jump Force" in terms of determining how high the player can jump (to a limit) - for example (if your "space bar" is the jump key, holding it down could build up "Jump Power" to a certain point/maximum) - a bit like "shot power" in football. Or, you could have more than one jump key (jump/bigger jump). If you have other "AI" players in the game (it doesn't matter if you don't) they could have various "Jump Power" limits, so that some are better than others (just like real-life basket-ball players). The "Jump Force" could also be applied to how far forward you/they can jump - again it can have "Jump Power". The whole "Jump Force" issue is it makes your game more realistic regardless (but it isn't necessary). However, if your "gaps" are at varying widths and/or heights from each other (and don't worry if they are not - they don't have to be) then it could help with the gameplay - if you have to wait for "Jump Power" to grow before jumping a larger gap then, perhaps the "AI" player could take the ball (or whatever it is) off you. If the game plays over various levels (which you are possibly doing when you said "it is based in demon scenes"???) you can increase the "Jump Power" variables at the end of each level to show an increase in the player's/"AI"'s skills. Have a think about this - let me know (either way - in your own time) if it did or didn't help - it doesn't matter if it didn't help you. |
| ||
"Goober" - I forgot: I wanted you to have a copy of your initial code to put in a solution to your initial problem (which seems to be the thing you need the most): You wanted to be able to jump without being able to jump until you have landed - ie. you don't want to jump, then press the "Jump" key and find that you "re-jump" while already jumping. In simple terms (there is more than one way of doing it): Have a variable (you may need to make it "Global") to work out if you are jumping or not - you could call it "Jumping" - don't assign a value to it - it needs to equal "0" Based on the fact that "Jumping is set at "0" If Jumping=0 and "you pressed jump" (to legally jump) - you can set "Jumping to "1" and jump Because jumping is now set to "1" - you won't be able to re-jump as your jump key will only work if Jumping="0" When you land - ie. collide with the floor/or your height value reaches it's minimum again (assuming you are playing on a flat level), you can reset Jumping to "0" Now that jumping is "0" again, your Jump key will work again I've written it like this to help you understand the "logic" of what you were initially asking. Let me know if it doesn't help. |
| ||
I'm sorry for taking so long to reply but i wans not online at the time.puki you asked for me to explain the gaps to you well it will have both ledge types the ones with it getting higher and where it is the same height. mean while i will read over your help and Ross C's help and see if i can get myself to understand it cause i haven't got round to reading it yet but will in about 3 minutes. |
| ||
Ok Ross C i read your help piece and then i tryed adding it to my code but it does not work do you think you could please make a piece of coding that uses gravity and the linepick command so i know where it goes and how i am meant to use it. puki i'm just going onto your help now. tell you how it went soon. |
| ||
Ok, i'll try and put something together :) |
| ||
Ok Goober. Here it is :) Use the arrow keys to move and the space bar to jump!Graphics3D 800,600 SetBuffer BackBuffer() Global camera=CreateCamera() Global light=CreateLight() Global player=CreateCone() EntityType player,1 EntityRadius player,1 EntityColor player,50,70,255 PositionEntity player,0,0.5,0 PositionEntity camera,0,2,-6 Global tex=CreateTexture(64,64,1+8) SetBuffer TextureBuffer(tex) For loop=0 To 3000 Color Rnd(190,255),Rnd(190,255),Rnd(190,255) Rect Int(Rnd(0,63)),Int(Rnd(0,63)),1,1 Next Color 255,255,255 SetBuffer BackBuffer() Global plane=CreatePlane() EntityType plane,2 EntityColor plane,200,100,120 EntityTexture plane,tex EntityPickMode plane,2 Global cube=CreateCube() PositionEntity cube,0,1,10 EntityPickMode cube,2 EntityType cube,2 Global cube1=CreateCube() PositionEntity cube1,0,3,12 EntityPickMode cube1,2 EntityType cube1,2 Global cube2=CreateCube() PositionEntity cube2,0,5,14 EntityPickMode cube2,2 EntityType cube2,2 Global sphere=CreateSphere(10) ScaleEntity sphere,10,1,10 EntityPickMode sphere,2 EntityType sphere,2 PositionEntity sphere,-2,0,19 Collisions 1,2,2,2; set up collisions between the ground and the player Global jump_force# Global jump_flag=0; set jump flag to 'no jump' Global gravity#=0.9; set gravity value While Not KeyHit(1) LinePick(EntityX(player,True),EntityY(player,True),EntityZ(player,True),0,-10,0); do a linepick straight down form the players location If jump_flag=0 Then If EntityY#(player,True)-PickedY()>1.05 Then; WARNING. THIS NUMBER MUST BE SLIGHTLY LARGER THAN THE PLAYERS ENTITYRADIUS. ; ABOVE. if the players y position is greater than a distance of 1.05, then make the player fall. ; Since the players entity radius is 1, This number must be slightly greater than 1, so that the collision ; system doesn't work. jump_flag=1; set jump flag to jump jump_force=0.02; set jump force to 0.02. You cannot set this to 0. It must always be slightly more End If End If If KeyHit(57) And jump_flag=0 Then; if user presses spacebar jump_flag=1; set jump flag to 'jump' jump_force=0.4; set jumping force. make larger for higher jump End If If KeyDown(200) Then MoveEntity player,0,0,0.1 If KeyDown(208) Then MoveEntity player,0,0,-0.1 If KeyDown(203) Then TurnEntity player,0,1,0 If KeyDown(205) Then TurnEntity player,0,-1,0 If jump_flag=1 Then; if jump flag set then 'jump' update_jump() End If update_camera() UpdateWorld RenderWorld Text 0,0," Press Space to jump. Arrow keys to move!" ;DebugLog(" pickedy="+PickedY()) Flip Wend End Function update_camera() RotateEntity camera,EntityPitch(player),EntityYaw(player),EntityRoll(player); make the camera equal to the rotations of the camera PositionEntity camera,EntityX(player),EntityY(player)+2,EntityZ(player); position the camera at the x and z pos of the player MoveEntity camera,0,0,-7; move the camera back from the player by 7 units PointEntity camera,player End Function Function update_jump() jump_force=jump_force*gravity; apply gravity to the jumping force MoveEntity player,0,jump_force,0; move the player If jump_force>0 And jump_force<0.05 Then; when players upward speed reaches alomost zero, reverse it ; make smaller to keep player in the air for longer jump_force=jump_force*-1; reverse the jumping force gravity=gravity+(2*(1-gravity)); turn gravity around End If If jump_force<-0.5 Then jump_force=-0.5; stop the player from falling to quick If EntityCollided(player,2) Then; if the player has collided with the ground If EntityY(player,True)-PickedY()<0.95 Then; WARNING. THIS NUMBER MOUST BE SLIGHTLY SMALLER THAN THE PLAYER'S ENTITYRADIUS jump_force=0; reset the jumping force jump_flag=0; reset jump flag back to zero (not jumping) gravity=gravity-(2*(gravity-1)); reset gravity End If End If End Function |
| ||
Nice code i think i will be able to get it to work now and i shall also study your code and learn it. |
| ||
You can add periods now. -me |
| ||
Peroids? What do you mean? Add them where? |
| ||
Peroids? What do you mean? Add them where? LMAO :D |