Hey Guys,
in my program I have an MMO/RTS style cam set up that allows you to orbit your character when you hold mouse2 and allows you to perform a point and click movement on mouse 1. After some doing, Ive managed to use spark's dll to get my character to walk on a modeled terrain .x object. Admittedly Im new to using sparky's and Ive spent a few hours trying to figure out the examples with marginal success.
My #1 problem is this: the waypoint point and click system works fine for movement but I cant get the waypoint object to follow the .x terrain. any thoughts on process,setup, etc.. is greatly appreciated.
here is an image to illustrate the waypoint problem.
this is the code Im using for waypoint control it might look familiar to someone, as I found it in an example:
` This bit calculates the 2d to 3d coordinates and positions the waypoint (object 8)
mmcoord:
scrw# = screen width()
scrh# = screen height()
smax# = r#*tan(FOV#/2)
sh# = (((scrh#/2-mousey())*2)/scrh#)*smax#
l# = (sh#*sin(90+atan(sh#/r#)))/sin(ax#-atan(sh#/r#))
smax2# = r#*scrw#/scrh#*tan(FOV#/2)
sw# = (((mousex()-scrw#/2)*2)/scrw#)*smax2#
rsh# = sqrt(r#^2+sh#^2)
rl# = sqrt((camera position x()-(ox#-l#*sin(ay#)))^2+(camera position y()-oy#)^2+(camera position z()-(oz#-l#*cos(ay#)))^2)
w# = (sw#*rl#)/rsh#
x# = ox#-l#*sin(ay#)-w#*cos(ay#)
y# = oy#
z# = oz#-l#*cos(ay#)+w#*sin(ay#)
position object 8,x#,y#,z#
heres the function that positions the player object (2):
moveplayer:
rem rotate player with mouse
if mouseclick()=2
yrotate object 2,object angle y(2)+mousemovex()/3.0
xrotate object 2,object angle x(2)+mousemovey()/3.0
endif
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
rem apply gravity, and user changes to movement
angy# = object angle y(2)
vx# = 0
vz# = 0
rem if player is jumping or falling then apply 'normal' gravity
rem if not attempt to keep the player stuck to the floor
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
rem only jump if on ground, and a certain time after last jump
if ground=1
if spacekey()=1 and jumptimer=0 then vy# = vy# + 3.0 : jumptimer = 20
endif
rem this would be the player's final position without collision
x# = oldx#+vx#
y# = oldy#+vy#
z# = oldz#+vz#
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
rem how flat is this ground
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
rem FLAT, stick
oldy# = sc_getStaticCollisionY()
else
rem STEEP, slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
rem ny#<0 means the player has hit a ceiling rather than a floor
if ny#>slope#
rem only on ground if standing on flat ground
ground = 1
vy# = 0
else
ground = 0
rem if player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then vy# = gravity#
endif
else
rem nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + vy#
ground = 0
endif
rem jumptimer will decrease only when player is back on ground
rem creates a pause between two successive jumps
if ground = 1 and jumptimer>0 then dec jumptimer
rem handle horizontal movement as sliding
rem player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
rem possible code for giving the player a jumping help up stairs...
rem might be useful if slope# is set very high but stairs are still required
`dy# = oldy#-sc_getStaticCollisionY()
`if dy#<slope# and dy#>0 and ground=1 then vy# = 0.5
endif
`point camera object position x(2),object position y(2),object position z(2)
position object 2,x#,oldy#,z#
position object 10,object position x(2),object position y(2)-5,object position z(2)
position object 11,object position x(2),object position y(2)-5,object position z(2)
sc_updateObject 2
return
problem #2
how do I get my character to face JUST the Y direction of the waypoint object. Currently using
point object char_state#, object position x(8), object position y(8), object position z(8)
but this doesnt keep my main character verticle if the waypoint is at another height.
any help is greatly appreciated.