Re: your first post. You set the Y to -50.0, and it should have been 50.0. Might have made the difference.
Quote: "
Just two items I need help with. The camera is pointing some degrees low and not straight ahead. If I try to yrotate either the camera or object, movement sends me to the ceiling.
"
Easily fixed. In the MovePlayer() function, look at this code:
position camera cx#,cy# + 7.5,cz#
set camera to object orientation player
move camera -20.0
point camera cx#,cy#,cz#
Change it to point camera cx#,cy# + 7.5,cz#. At that point, your camera will be pointing straight ahead. (I changed this in the code I am posting to be 25.0, which seems to work better). Just make the camera Y that you are pointing at the same as it's Y position.
I don't understand what you are saying with regard to yrotating the camera or object sending you to the ceiling. The camera location and position is based upon the player's position. The player object rotates with the mouse. Need clarification.
Quote: "Also is there a way to hide the object without having that sphere in line of sight all the time?"
yes, just use the HIDE OBJECT command right after you create the player object. The object is still there, you just won't see it.
In the latest code you took out the gravity#. You really need that. If you are trying to keep the camera higher, you could always change the code in the MovePlayer() function to do this (add more than 7.5 to cy#). Bear in mind, the collision checks are on the player sphere; if you are considerably higher than it, the camera might go through some low entryways. I ran it at cy# + 25.0 and it seemed to work okay, so I changed the code. I made the player's sphere larger too.
There is a command that states it can keep the camera from colliding with a static object. It is SET CAMERA TO FOLLOW X, Y, Z, Angle, Distance, Height, Smooth, Collision. However, I have not been able to get this to work with Sparky's - I think you have to use DBP's native MAKE STATIC OBJECT and associated collision boxes to make it work. I would not recommend using this, but wanted to mention it to you. I recommend you make a second sphere object for the camera that will perform the same collision checks as is done for the player. I made the player and camera spheres at a size of 20, increased the radius for both and ran it. It works pretty well for keeping the camera from going out of bounds. Here is the code that worked for me:
Rem ***** Main Source File *****
hide mouse
sync on
autocam off
global gravity# as float, radius# as float, pspeed# as float, CamRadius#
global player, world, CamObj
gravity# = 0.5 : radius# = 10.0 : pspeed# = 1.0 : world = 5 : player = 6
CamObj = 7 : CamRadius# = 10.0
set dir "Files"
load object "levelbank\testlevel\universe.dbo",world,3
sc_SetupComplexObject world,1,25
make object sphere player,20
`color object player,rgb(0,0,0)
`ghost object on player
position object player,271.5,40.0,-165.4
sc_SetupObject player,2,1
hide object player
make object sphere CamObj,20
sc_SetupObject CamObj,3,1
hide object CamObj
`position camera 700,60,-700
range=5000
red=64
green=64
blue=128
`camreaangle# = 90.0
`yrotate camera 0,wrapvalue(camera angle y() + camreaangle# )
sync rate 60
set dir ".."
Load image "media/sky.jpg",1
MAKE OBJECT SPHERE 1,-6000,50,50
Texture object 1,1
set ambient light 75
color ambient light rgb(red,green,blue)
set camera range 0,1,range
do
MovePlayer()
sync
loop
end
function MovePlayer()
rem store old coordinates
px# = object position x(player)
py# = object position y(player)
pz# = object position z(player)
rem get user input
fwd = keystate(17) : rem W key to move forward
bwd = keystate(31) : rem S key to move backward
ay# = object angle y(player)
ay# = wrapvalue(ay# + (mousemovex() * .13) )
yrotate object player,ay#
if fwd = 1 then move object player,pspeed#
if bwd = 1 then move object player,-pspeed#
rem get current coordinates of the player
cx# = object position x(player)
cy# = object position y(player)
cz# = object position z(player)
collide = sc_SphereSlide(world,px#,py#,pz#,cx#,cy#,cz#,radius#,0)
if collide > 0
rem collided with world - get new coordinates
sx# = sc_GetCollisionSlideX()
sy# = sc_GetCollisionSlideY()
sz# = sc_GetCollisionSlideZ()
position object player,sx#,sy#,sz#
rem hit the ground - reset gravity
gravity# = 0.5
else
rem no collision - apply gravity
if gravity# < 10.0 then inc gravity#,.02
dec cy#,gravity#
position object player,cx#,cy#,cz# : rem recheck to make sure it is okay
sc_UpdateObject player
collide = sc_SphereSlide(world,px#,py#,pz#,cx#,cy#,cz#,radius#,0)
if collide > 0
sx# = sc_GetCollisionSlideX()
sy# = sc_GetCollisionSlideY()
sz# = sc_GetCollisionSlideZ()
position object player,sx#,sy#,sz#
rem hit the ground - reset gravity
gravity# = 0.5
endif
endif
sc_UpdateObject player
rem position camera behind player
cx# = object position x(player)
cy# = object position y(player)
cz# = object position z(player)
OldX# = object position x(CamObj)
OldY# = object position y(CamObj)
OldZ# = object position z(CamObj)
position object CamObj,cx#,cy# + 25.0,cz#
set object to object orientation CamObj, player
move object CamObj,-20.0
`move camera -20.0
sc_UpdateObject CamObj
NewX# = object position x(CamObj)
NewY# = object position y(CamObj)
NewZ# = object position z(CamObj)
collide = sc_SphereSlide(world,OldX#,OldY#,OldZ#,NewX#,NewY#,NewZ#,CamRadius#,0)
if collide > 0
NewX# = sc_GetCollisionSlideX()
NewY# = sc_GetCollisionSlideY()
NewZ# = sc_GetCollisionSlideZ()
endif
position camera NewX#,NewY#,NewZ#
point camera cx#,NewY#,cz#
endfunction
So many games to code.....so little time.