Collision Questions
Blitz3D Forums/Blitz3D Beginners Area/Collision Questions
| ||
I am trying to "fly" a ship over a track with a small hill in Wipeout style. But for some reason the ship either flys THROUGH the hill or just stops at it. Could someone take a look at my code and tell me if there is an obvious mistake as I have only been at Blitz3D for 2 days and I really am struggling with this collision lark :( The code is a bit of rehash from the driver example as well as one of the sample programs that shows how to load an object. I really would appreicate any help on this as this is really annoying me at the moment to the point I want to kick the computer in (not a good idea I know!!! :-D) Thanks Max ; Racer Test Program V1.1 ; April 2005 ; This program is a rehash of two program to try and get a ship to fly around ; a pre-made track. Graphics3D 800,600,16,2 SetBuffer BackBuffer() ; Setup contants and varibles as used in the driver example and modified for what I think I need. Const GRAVITY#=-.01 Const BODY=1,WALL=2,RACETRACK=3 Collisions BODY,RACETRACK,2,2 Collisions BODY,WALL,2,1 ; Load required Track & Walls and set them up as needed. This includes linking to any variables. track=LoadMesh ("Media/TestTrack2a.3ds") walls=LoadMesh ("Media/TestTrack2b.3ds") PositionEntity track,0,0,0 PositionEntity walls,0,0,0 RotateEntity track,0,0,-90 RotateEntity walls,0,0,-90 EntityType track,RACETRACK EntityType walls,WALL ; Now do the same for the ship (this replaces the car in the driver example). ship=LoadMesh ("Media/fighter.3ds") PositionEntity ship,0,0,0 EntityShininess ship,1 EntityType ship,BODY ; Set up a pivot point for the ship now. Hopefully this will poisition the pivot under the ship ; and will enable the ship to "float" over the track in Wipeout style. target=CreatePivot(ship) PositionEntity target,0,-5,0 ; Set up the main light for the scene. light=CreateLight() PositionEntity (light,0,10,-10) ; Now get the camera up and running... camera=CreateCamera() CameraRange camera,1,100000 CameraFogMode camera,1 CameraFogRange camera,2000,90000 PositionEntity camera,0,500,1500 PointEntity camera,ship ; Setup other variables camx#=0 ; Camera X Angle. camy#=0 ; Camera Y Angle. camz#=0 ; Camera Z Angle. pitch#=0 ; Camera & Ship Rotation Angle. While Not KeyHit(1) ;move ship If KeyDown(203) camy=camy+3 TurnEntity ship,0,3,0 EndIf If KeyDown(205) camy=camy-3 TurnEntity ship,0,-3,0 EndIf If KeyDown(200) MoveEntity ship,0,0,-800 EndIf ; Reset camera position and view. PositionEntity camera,EntityX(ship),EntityY(ship),EntityZ(ship) RotateEntity camera,0,camy,pitch MoveEntity camera,0,500,1500 PointEntity camera,ship UpdateWorld RenderWorld Text 320,500,"Racer Demo V1.1" Flip Wend End If you want the files it loads they should be here! |
| ||
I've not run your code. However, 'MoveEntity ship,0,0,-800' is a VERY large step. Should it be -8? |
| ||
No, make no mistake the track is HUGE in comparason to the ship. If it is less than a step of 500 it runs like a snail! Due to physical size, not complexity. Max |
| ||
Mmm, I'm not sure it is advisable to move your ship in units of 800 - especially in a huge world - that possibly could interfere with collision accuracy - coz every 10 of your 'units', you have moved 8,800 in Blitz. |
| ||
So would it be best to scale everything down somewhat then? Would that help at all? |
| ||
Scaling will probably be a good idea. Another factor will be if your 'ship' can actually, 'slide' over the 'hill' - if it is too steep, it won't coz of the gravity being applied - you could try amending your gravity. If this works then just amend gravity at the point of going up the hill. You can also test this by changing the gradient of the hill - to see how this works with the gravity applied - experiment with this. EDIT: your problem could be a combination of this and the scaling. |
| ||
Ok, still cannot get this to work. Wondered about the gravity thing as it wasn't acutally doing anything. So I borrowed the code from the driver demo and insterted it, changing the names as required. So instead of having this: If KeyDown(200) MoveEntity ship,0,0,-800 EndIf I have this If EntityCollided( ship,RACETRACK ) If KeyDown(200) speed=speed+20 If speed>700 speed=700 Else If KeyDown(208) speed=speed-20 If speed<-.5 speed=-.5 Else speed=speed*100 EndIf MoveEntity ship,0,0,speed TranslateEntity ship,0,GRAVITY,0 Else TranslateEntity ship,x_vel,y_vel+GRAVITY,z_vel EndIf but the above code won't do anything at all. The ship just stays total still :( I appreicate the values are really high, but I wanted to make the ship move before trying to scale it all down. Any more ideas anyone? Please? |
| ||
If you just inserted that code into the code above it will not work because in this line, TranslateEntity ship,x_vel,y_vel+GRAVITY,z_vel x_vel,y_vel+GRAVITY,z_vel is saying TranslateEntity ship,0,gravity,0. So you need to update those variables somehow. Also in your code above, you do realize you are moving backwards? Of course thats beside the point. Where you have If keydown 200 make it something like if keydown 200 y_vel= y_vel + speed end if Also I think you should scale down everything first, just to count that out as a potential problem. Good luck. |