Ok, i have had a look at this.
Firstly, your jeep and car are made out of many parts. They aren't centred either, so this is causing some collision issues. When using entitytype, using the recursive flag so it sets all parts to have collisions.
Same problem with your shop i believe
For some reason your camera was pointing downwards?
Try and give all your extracted animations a variable assignment. Makes it easier to keep track of whats what :o)
Indent your code better. Every IF statements contents should probably be indented by al least a tab. Keeps it consistant and easily readable.
Make your variables GLOBAL if you intend to use them throughout your code. If you add functions to that code, many of your variable setting would be over written, or worse, shared.
I shared your problem with hideentity. Not sure what that was about, but i buggered something up. Problably a variable problem.
I implemented a better camera system, one that doesn't rely on setting up a parent. You simply pass across the entity you want the camera to follow every frame. You can change entities and it will smoothly translate.
You need to put your vehicles into a type collection, or array system (Types are easier to read). Reason being, you have hardcoded variable names and don't really know how many vehicles you have, or have any easy way of individually checking them. I have implemented a type system to hold your cars. When the SPACEBAR is pressed, it does a distance check against all the cars and returns the closest car. You simply do a distance check against the returned entity to see if it is in range or not.
I put alot of stuff into functions to ease reading and enable you to see whats going on better.
I think that's all. I completely rewrote your code too, sorry about that, but it's easier for me to do that than try and modify yours :o) I haven't commented everything, just the things i have really changed.
Oh, i added a speed variable to your vehicles, so they accelerate and decelerate. Pretty basic stuff. Just to get you started.
; Game
; ---------------------
AppTitle "Game"
Graphics3D 1024,768,32,2
SetBuffer BackBuffer()
;Collision Group
Global Player=1
Global Obstacle=2
Global Ground=3
Global Car=4
;The controlable Character
Global char=LoadAnimMesh("dwarf2.b3d")
Global chartex=LoadTexture("dwarf2.jpg")
PositionEntity char,-38,19,202
ScaleEntity char,.085,.085,.085
EntityType char,Player
EntityRadius char,1
;Camera
Global cam1=CreateCamera()
PositionEntity cam1,EntityX(char),EntityY(char)+4.5,EntityZ(char)-7
Global cam_piv = CreatePivot()
Global cam_target = CreatePivot()
Global cam_target_chase = CreatePivot()
EntityParent cam_piv,cam_target
PositionEntity cam_piv,0,8,-6
; The below values: The lower they are, the fast the camera will react.
Global chase_target_speed# = 20 ; the speed the camera pivot will catch up with the current camera target
Global chase_speed# = 30 ; the speed the camera will catch up with the camera pivot
;Light
lite1=CreateLight(1)
RotateEntity lite1,90,0,0
;Tree2
tree2=LoadMesh("Tree1.3ds")
PositionEntity tree2, -20,5,116
ScaleEntity tree2,.05,.05,.05
EntityType tree2,Obstacle
;cage
cage=LoadMesh("thecage.3ds")
ScaleEntity cage,.040,.040,.040
PositionEntity cage,EntityX(tree2)+4,EntityY(tree2)+1.2,EntityZ(tree2)-2
Global metal=LoadTexture("metal.jpg")
EntityTexture cage,metal
Type vehicle
Field entity
Field speed#
End Type
;The red car
v.vehicle = New vehicle
v\entity = LoadMesh("f360.3ds")
Cartex = LoadTexture("fskin.jpg")
EntityTexture v\entity,Cartex
PositionEntity v\entity,-41,7,175
EntityRadius v\entity,1
EntityType v\entity,Car,True
RotateEntity v\entity,0,35,0
; centre the mesh to the 0,0,0 axis
FitMesh v\entity,-MeshWidth(v\entity)/2,-MeshHeight(v\entity)/2,-MeshDepth(v\entity)/2,MeshWidth(v\entity),MeshHeight(v\entity),MeshDepth(v\entity)
ScaleEntity v\entity,2,2,2
;The green jeep
v.vehicle = New vehicle
v\entity = LoadMesh("jeep1.3ds")
jeep1tex = LoadTexture("jeep1.jpg")
EntityTexture v\entity,jeep1tex
PositionEntity v\entity,-67,8,200
EntityType v\entity,car,True
EntityRadius v\entity,1
; centre the mesh to the 0,0,0 axis
FitMesh v\entity,-MeshWidth(v\entity)/2,-MeshHeight(v\entity)/2,-MeshDepth(v\entity)/2,MeshWidth(v\entity),MeshHeight(v\entity),MeshDepth(v\entity)
ScaleEntity v\entity,0.8,0.8,0.8
;Weapon shop
weapshop=LoadMesh("weapshop.3ds")
weapshoptex=LoadTexture("weapshop.jpg")
EntityTexture weapshop,weapshoptex
PositionEntity weapshop,-59,12.5,178
RotateEntity weapshop,0,90,0
ScaleEntity weapshop,.5,.5,.5
EntityType weapshop,Obstacle
;weapon shop owner
wso=LoadAnimMesh("dwarf1.b3d")
wsotex=LoadTexture("dwarf.jpg")
EntityTexture wso,wsotex
PositionEntity wso,EntityX(weapshop)+1.5,6,EntityZ(weapshop)-2
ScaleEntity wso,.085,.085,.085
EntityType wso,Player
RotateEntity wso,0,-90,0
EntityRadius wso,.2
; shop
shop=LoadMesh("shop.3ds")
shoptex=LoadTexture("shop.jpg")
EntityTexture shop,shoptex
PositionEntity shop,-30,12.5,174
RotateMesh shop,0,270,0
ScaleMesh shop,.5,.5,.5
EntityType shop,Obstacle
;Creating the sky
sky = CreateSphere(60)
FlipMesh sky
ScaleEntity sky,700,700,700
PositionEntity sky, 0,70,0
sky_tex = LoadTexture ( "sky.bmp" )
EntityTexture sky,sky_tex
;EntityParent sky,char
;Making water
water_tex=LoadTexture( "water1.jpg" )
ScaleTexture water_tex,6,6
water=CreatePlane()
EntityTexture water,water_tex
PositionEntity water,0,2,0
EntityAlpha water,.5
ScaleEntity water,5,100,5
;loading the terrain
terrain=LoadTerrain ( "HMAP.jpg" )
ScaleEntity terrain,5,100,5
PositionEntity terrain,-758,-21.7,-500
tex=LoadTexture( "GRASS1.jpg" )
EntityTexture terrain,tex
EntityType terrain,Ground
;Animation extracting
;run
Global char_run_anim = ExtractAnimSeq(char,16,26)
;idle
Global char_idle_anim = ExtractAnimSeq (char,292,325)
;attack
Global char_attack_anim = ExtractAnimSeq (char,62,180)
Global shopkeeper_idle_anim = ExtractAnimSeq (wso,292,325)
Global mode = 0 ; 0 = Control Character
; 1 = Control Car
Global entry_distance = 8 ; the distance you need to be to enter a car.
Global nearest_vehicle ; the vehicle you are nearest too
Global driving_vehicle ; the vehicle you are in control of. Set to null if none.
Global drive_speed# = 0 ; the speed the car travels at
Collisions 1,2,2,2
Collisions 1,3,2,2
Collisions 1,4,2,2
While Not KeyHit(1)
check_mode_control() ; check to see if the SPACEBAR has been pushed to drive a car or exit one.
If mode = 0 Then
character_control()
ElseIf mode = 1 Then
vehicle_controls()
End If
; slow down the car speed regardless of if the player is in it, or has ever been in it. This is so if the player
; jumps out at speed, the car keeps on going but slows down.
If drive_speed > 0.01 Then ; if the cars speed is greater than zero, slow it down
drive_speed = drive_speed - 0.02
If drive_speed < 0 Then drive_speed = 0 ; if it slows down to below zero, set to 0
ElseIf drive_speed < -0.01 Then ; if the cars speed is less than zero, speed it up
drive_speed = drive_speed + 0.02
If drive_speed > 0 Then drive_speed = 0 ; as above
Else
drive_speed = 0
End If
; only attempt to move the actual vehicle if it has been driven once. Else the variable holding the driven car
; be set to zero, and it will generate an error.
If driving_vehicle <> 0 Then
;DebugLog(" driving vehicle = "+driving_vehicle+" speed : "+drive_Speed)
MoveEntity driving_vehicle,0,0,drive_speed
End If
UpdateWorld
RenderWorld
Flip
Wend
End
;This function checks the space bar to switch between character and vehicle control, by setting the mode variable.
Function check_mode_control()
If KeyHit(57) Then
If mode = 0 Then
nearest_vehicle = check_nearest()
If EntityDistance(char,nearest_vehicle) < entry_distance Then
driving_vehicle = nearest_vehicle
mode = 1
EntityParent char,driving_vehicle
HideEntity char
DebugLog(" hiding char")
End If
ElseIf mode = 1 Then
mode = 0
ShowEntity char
EntityParent char,0
End If
End If
End Function
; This is the function for character control
Function character_control()
If KeyDown(200) Then
If AnimSeq(char) <> char_run_anim Then
Animate char,1,.2,char_run_anim,4
Else
MoveEntity char,0,0,0.5
End If
Else
If AnimSeq(char) <> char_idle_anim Then
Animate char,1,.2,char_idle_anim,4
End If
End If
If KeyDown(203) Then RotateEntity char,EntityPitch(char,True),EntityYaw(char,True)+2,EntityRoll(char,True)
If KeyDown(205) Then RotateEntity char,EntityPitch(char,True),EntityYaw(char,True)-2,EntityRoll(char,True)
MoveEntity char,0,-2,0
update_camera(char)
End Function
; This is the function for vehicle control
Function vehicle_controls()
If KeyDown(200) And mode = 1 Then
drive_speed = drive_speed + 0.04
DebugLog("Moving car : "+drive_Speed)
ElseIf KeyDown(208) Then
drive_speed = drive_speed -0.04
End If
If KeyDown(203) Then RotateEntity driving_vehicle,EntityPitch(driving_vehicle,True),EntityYaw(driving_vehicle,True)+2,EntityRoll(driving_vehicle,True)
If KeyDown(205) Then RotateEntity driving_vehicle,EntityPitch(driving_vehicle,True),EntityYaw(driving_vehicle,True)-2,EntityRoll(driving_vehicle,True)
update_camera(driving_vehicle)
End Function
; This function checks all vehicles and return the nearest vehicle to the player
Function check_nearest()
Local n_vehicle = 0 ; the closest vehicle so far
Local n_distance# = 99999999 ; the closest distance so far. Set to very high so close distance is found
Local flag = 0 ; set to 1 when entity is found. So at the end of the function we can tell if anything was found.
For v.vehicle = Each vehicle
; check the distance between the player and the vehicle. If it's less than the smallest distance recorded,
; then it is the nearest vehicle so far.
If EntityDistance(char,v\entity) < n_distance Then
n_distance = EntityDistance(char,v\entity) ; set smallest distance so far
n_vehicle = v\entity ; set the nearest vehicle variable to the entity handle of this type object.
flag = 1
End If
Next
If flag = 1 Then ; if a vehicle was found then
Return n_vehicle ; return the nearest vehicle
Else
Return 0 ; return 0 if no vehicles found
End If
End Function
; smooth moving camera function. Uses 3 pivots.
; cam_target is the pivot the camera will always rest to view on. It is set to the entity you want to follow.
; It will always match it's position and rotation
; without parenting to it.
;
; cam_target_chase is a pivot that constantly moves toward the target pivot above. The camera is always pointing to it
; It moves so when the target is
; switched, the camera doesn't
; jump to the next target.
; I changed the Y position of this
; pivot so to adjust the point the
; camera points to, as it was too
; low.
; cam_piv is a pivot that is parented to the target pivot. It never needs moved, as it is parented, and follows
; the target whereever it goes.
; The camera always moves toward it.
; It is the resting POSITION of the camera, so by adjusting
; it's position relative to the target pivot, you can,
; adjust the view height, and view distance.
;
; The camera itself will point towards the cam_piv, move towards it, then point to the cam_target_chase pivot.
; Since there is NO render during this point, the camera's change of view is never recorded. It's only for
; movement purposes.
Function update_camera(target)
PositionEntity cam_target,EntityX(target,True),EntityY(target,True),EntityZ(target,True)
RotateEntity cam_target,EntityPitch(target,True),EntityYaw(target,True),EntityRoll(target,True)
PointEntity cam_target_chase,cam_target
MoveEntity cam_target_chase,0,0,EntityDistance(cam_target_chase,cam_target)/chase_target_speed
PositionEntity cam_target_chase,EntityX(cam_target_chase),EntityY(cam_target)+5,EntityZ(cam_target_chase)
PointEntity cam1,cam_piv
MoveEntity cam1,0,0,EntityDistance(cam_piv,cam1)/chase_speed
PointEntity cam1,cam_target_chase
End Function