Ok, i'm gonna put this in here cuz I don't want Van B banning me, so here goes. I've added some terrain to my game (horribly done I know), but I need to know how to make it so when u walk on that terrain, the player aligns to the terrain's vector, and rotates with the hill.
Code:
Rem Project: 3dhptest
Rem Created: Sunday, August 08, 2010
Rem ***** Main Source File *****
sync on : sync rate 60
autocam off
set ambient light 100
type player
health# as float
actualhealth# as float
maxhealth# as float
magic# as float
actualmagic# as float
maxmagic# as float
X# as float
Y# as float
Z# as float
Speed# as float
TSpeed# as float
id as integer
endtype
type enemy
health# as float
actualhealth# as float
maxhealth# as float
magic# as float
actualmagic# as float
maxmagic# as float
X# as float
Y# as float
Z# as float
Speed# as float
TSpeed# as float
id as integer
endtype
type menu
id as integer
endtype
type vector
id as integer
endtype
type skyobject
id as integer
X# as float
Y# as float
Z# as float
Xsize# as float
Ysize# as float
Zsize# as float
Size# as float
R# as float
G# as float
B# as float
A# as float
XSegs as integer
ZSegs as integer
cull as boolean
smoothness# as float
visibility# as float
endtype
type terrain
X# as float
Y# as float
Z# as float
XSize# as float
YSize# as float
ZSize# as float
texture as integer
detail as integer
ground as integer
endtype
fog on
global texture
global detail
global ground
#constant healthtube 1
#constant healthbarleftside 2
#constant healthbarrightside 3
#constant healthbar 4
#constant playerid 5
#constant obj 6
#constant obj2 7
#constant obj3 8
#constant enemyid 9
#constant healthbarid 10
#constant magicbarid 11
#constant magicbar 12
#constant skyid 13
#constant terrainid 14
#constant vectorid 1
dim Landscape(20) as terrain
`Landscape(terrainid).id = find free object(terrainid, 100000)
Landscape(terrainid).X# = 0
Landscape(terrainid).Y# = -1
Landscape(terrainid).Z# = 1000
Landscape(terrainid).XSize# = 0
Landscape(terrainid).YSize# = 0
Landscape(terrainid).ZSize# = 0
Landscape(terrainid).texture = find free image(terrainid, 100000)
Landscape(terrainid).detail = find free image(terrainid, 100000)
Landscape(terrainid).ground = find free image(terrainid, 100000)
dim Sky(20) as skyobject
Sky(skyid).id=find free object(skyid, 100000)
Sky(skyid).Size#=1
Sky(skyid).XSize#=100000
Sky(skyid).YSize#=100000
Sky(skyid).ZSize#=100000
Sky(skyid).X#=0
Sky(skyid).Y#=0
Sky(skyid).Z#=0
Sky(skyid).R#=68
Sky(skyid).G#=207
Sky(skyid).B#=252
Sky(skyid).A#=255
Sky(skyid).XSegs = 100
Sky(skyid).ZSegs = 100
Sky(skyid).cull = 0
Sky(skyid).smoothness# = 100
Sky(skyid).visibility# = 100
if Sky(skyid).R#>255 then Sky(skyid).R#=255
if Sky(skyid).G#>255 then Sky(skyid).G#=255
if Sky(skyid).B#>255 then Sky(skyid).B#=255
if Sky(skyid).R#<0 then Sky(skyid).R#=0
if Sky(skyid).G#<0 then Sky(skyid).G#=0
if Sky(skyid).B#<0 then Sky(skyid).B#=0
if Sky(skyid).cull>1 then Sky(skyid).cull=1
if Sky(skyid).cull<0 then Sky(skyid).cull=0
if Sky(skyid).smoothness#>100 then Sky(skyid).smoothness#=100
if Sky(skyid).smoothness#<0 then Sky(skyid).smoothness#=0
if Sky(skyid).visibility#>100 then Sky(skyid).visibility#=100
if Sky(skyid).visibility#<0 then Sky(skyid).visibility#=0
make object sphere Sky(skyid).id,Sky(skyid).Size#,Sky(skyid).XSegs,Sky(skyid).ZSegs
position object Sky(skyid).id,Sky(skyid).X#,Sky(skyid).Y#,Sky(skyid).Z#
scale object Sky(skyid).id,Sky(skyid).XSize#,Sky(skyid).YSize#,Sky(skyid).ZSize#
cls rgbalpha(Sky(skyid).R#,Sky(skyid).G#,Sky(skyid).B#,Sky(skyid).A#) `clear screen to red
skyimg=find free image()
get image skyimg,0,0,1,1
texture object Sky(skyid).id,skyimg
set object cull Sky(skyid).id,Sky(skyid).cull
set object smoothing Sky(skyid).id,Sky(skyid).smoothness#
set alpha mapping on Sky(skyid).id,Sky(skyid).visibility#
global p as player
global e as enemy
dim menuImage(20) as menu
menuImage(healthtube).id=find free image(healthtube,100000)
menuImage(healthbarleftside).id=find free image(healthbarleftside,100000)
menuImage(healthbarrightside).id=find free image(healthbarrightside,100000)
menuImage(healthbar).id=find free image(healthbar,100000)
menuImage(magicbar).id=find free image(magicbar,100000)
dim Object(20) as player
Object(playerid).id=find free object(playerid,100000)
Object(obj).id=find free object(obj,100000)
Object(obj2).id=find free object(obj2,100000)
Object(obj3).id=find free object(obj3,100000)
`if mousex()>[img pos x] and mousex()<[img pos x+size x] and mousey()>[img pos y] and mousey()<[img pos y+size y]
Object(playerid).actualhealth#=100001
Object(playerid).health# = Object(playerid).actualhealth#
Object(playerid).maxhealth# = 100001
Object(playerid).actualmagic#=100001
Object(playerid).magic# = Object(playerid).actualmagic#
Object(playerid).maxmagic# = 100001
Object(playerid).X# = 0.0
Object(playerid).Y# = 1.0
Object(playerid).Z# = 0.0
if Object(playerid).magic#>Object(playerid).maxmagic# then Object(playerid).magic#=Object(playerid).maxmagic#
if Object(playerid).health#>Object(playerid).maxhealth# then Object(playerid).health#=Object(playerid).maxhealth#
dim Vec(20) as vector
Vec(vectorid).id=find free vector(vectorid,100000)
dim Object2(20) as enemy
Object2(enemyid).id=find free object(enemyid,100000)
Object2(enemyid).actualhealth#=10000
Object2(enemyid).health#=Object2(enemyid).actualhealth#
Object2(enemyid).maxhealth# = 2000000.0
Object2(enemyid).actualmagic#=10000
Object2(enemyid).magic#=Object2(enemyid).actualmagic#
Object2(enemyid).maxmagic# = 2000000.0
Object2(enemyid).X# = 0.0
Object2(enemyid).Y# = 1.0
Object2(enemyid).Z# = 0.0
global u#
global v#
LoadGame()
set camera range .1,9999999
do
x#=object position x(Object(playerid).id)
z#=object position z(Object(playerid).id)
x#=newxvalue(x#,a#,speed#)
z#=newzvalue(z#,a#,speed#)
xrotation#=object angle x(Landscape(terrainid).ground)
yrotation#=object angle y(Landscape(terrainid).ground)
zrotation#=object angle z(Landscape(terrainid).ground)
h#=get terrain ground height(Landscape(terrainid).ground,x#,z#)
position object Object(playerid).id,x#,h#,z#
rotate object Object(playerid).id,xrotation#,yrotation#,zrotation#
` yrotate object Object(playerid).id,a#
if upkey()=1 or keystate(17)=1 and speed#<1.2 then speed#=0.2
if downkey()=1 or keystate(31)=1 and speed#>-1.2 then speed#=-0.2
if leftkey()=1 or keystate(30)=1 then a#=wrapvalue(a#-1)
if rightkey()=1 or keystate(32)=1 then a#=wrapvalue(a#+1)
position object Sky(skyid).id,object position x(Object(playerid).id),object position y(Object(playerid).id),object position z(Object(playerid).id)
`Player 1's co-ordinates
X1# = object position x(Object(playerid).id)
Y1# = object position y(Object(playerid).id)
Z1# = object position z(Object(playerid).id)
Angle1# = object angle y(Object(playerid).id)
`Player 1's movement
`If upkey() = 1 or keystate(17) then Move object Object(playerid).id, .1
`If downkey() = 1 or keystate(31) then Move object Object(playerid).id, -.1
`If leftkey() = 1 or keystate(30) then Dec Angle1#, 1
`If rightkey() = 1 or keystate(32) then Inc Angle1#, 1
if downkey() or keystate(31) and object angle y(Object(playerid).id)=0
yrotate object Object(playerid).id,360
endif
Rotate object Object(playerid).id, 0, wrapvalue(Angle1#), 0
Set camera to follow X1#, Y1#, Z1#, Angle1#, 10, 4, 50, 1
`if object visible(Object(playerid).id)
if keystate(44) and (Object(playerid).health# > 0.0)
dec Object(playerid).health#,100
if Object(playerid).health#>Object(playerid).maxhealth#
Object(playerid).health#=Object(playerid).maxhealth#
endif
endif
if keystate(45) and (Object(playerid).health# < Object(playerid).maxhealth#)
inc Object(playerid).health#,100
if Object(playerid).health#<0
Object(playerid).health#=0
endif
endif
`endif
if GetDist(0,0,Object(playerid).id,Object2(enemyid).id)<10 and GetDist(1,0,Object(obj).id,0)>1.6
Show Object Object(playerid).id
Show Object Object(obj).id
Show Object Object(obj2).id
Show Object Object(obj3).id
else
hide Object Object(obj).id
hide Object Object(obj2).id
hide Object Object(obj3).id
endif
CreateBar(Object(healthbarid).id,0,0,10,menuImage(healthbar).id,0,0,100,10,Object(playerid).health#,rgbalpha(255,0,0,255),rgbalpha(255,255,0,255),Object(playerid).maxhealth#)
CreateBar(Object(magicbarid).id,0,0,0,menuImage(magicbar).id,0,20,100,10,Object(playerid).magic#,rgbalpha(68,207,0,255),rgbalpha(68,207,255,255),Object(playerid).maxmagic#)
text 10,50,"y:"+str$(object angle y(Object(playerid).id))
sync
loop
function load_objects()
`PLAYER
load object "mourner.dbo",Object(playerid).id
rotate object Object(playerid).id,0,-180,0
scale object Object(playerid).id,20,20,20
`ENEMY
make object cube Object2(enemyid).id,1
`PLAYER HEALTH
Make Object Plain Object(obj).id,1.25,.1
set object transparency Object(obj).id,1
fix object pivot Object(obj).id
position object Object(obj).id,0,0,10
set object light Object(obj).id,0
SET OBJECT FILTER Object(obj).id,0
set object smoothing Object(obj).id,100
CreateBar(Object(obj).id,1,0,0,Object(playerid).id,0,0,100,10,Object(playerid).health#,rgbalpha(255,0,0,255),rgbalpha(255,255,0,255), Object(playerid).maxhealth#)
hide object Object(obj).id
`PLAYER MAGIC
Make Object Plain Object(obj2).id,1.25,.1
set object transparency Object(obj2).id,1
fix object pivot Object(obj2).id
position object Object(obj2).id,0,4,2
set object light Object(obj2).id,0
SET OBJECT FILTER Object(obj2).id,0
set object smoothing Object(obj2).id,100
CreateBar(Object(obj2).id,1,0,0,Object(playerid).id,0,0,100,10,Object(playerid).magic#,rgbalpha(68,207,0,255),rgbalpha(68,207,255,255), Object(playerid).maxmagic#)
hide object Object(obj2).id
`ENEMY HEALTH
Make Object Plain Object(obj3).id,1.25,.1
set object transparency Object(obj3).id,1
fix object pivot Object(obj3).id
position object Object(obj3).id,0,0,5
set object light Object(obj3).id,0
SET OBJECT FILTER Object(obj3).id,0
set object smoothing Object(obj3).id,100
CreateBar(Object(obj3).id,1,0,0,Object2(enemyid).id,0,0,100,10,Object2(enemyid).health#,rgbalpha(255,0,0,255),rgbalpha(255,255,0,255), Object2(enemyid).maxhealth#)
hide object Object(obj3).id
endfunction
function bar(x, y, width, height, load$, P#)
P# = P#/100
if P#<0.0 then P#=0.0
rem gradient bar
seg = width / 3
box x, y, x+seg, y+height, rgb(0,0,0),rgb(0,0,0),rgb(85,0,0),rgb(85,0,0)
box x+seg, y, x+seg+seg, y+height, rgb(85,0,0),rgb(85,0,0),rgb(170,0,0),rgb(170,0,0)
box x+seg+seg, y, x+width, y+height, rgb(170,0,0),rgb(170,0,0),rgb(255,0,0),rgb(255,0,0)
rem empty bit
ink rgb(92,92,92),0
box x+width*P#, y, x+width, y+height
rem highlight
c1 = 0xCCFFFFFF
c2 = 0x33FFFFFF
box x, y, x+width, y+height*0.5, c2,c1,c2,c1
ink rgb(255,255,255)
center text x,y,load$
endfunction
Function LoadGame()
load_images(menuImage(healthtube).id,menuImage(healthbarleftside).id,menuImage(healthbarrightside).id)
load_objects()
make mesh from object 1,Object(obj).id
make mesh from object 2,Object(obj2).id
make mesh from object 3,Object(obj3).id
make vector3 Vec(vectorid).id
texture = Landscape(terrainid).texture `Using a random here may cause problems! A 2 in a million chance of duplicates.
load image "terrain2hp.png",texture
detail = Landscape(terrainid).detail `Using a random here may cause problems
load image "detail.tga",detail
global ground
ground = Landscape(terrainid).ground `Using a random here may cause problems
make object terrain ground
set terrain heightmap ground, "terrain2h.bmp"
set terrain scale ground, 2, 0.15, 2
set terrain split ground, 16
set terrain tiling ground, 4 ` Looks better if you do some tiling IMHO
set terrain texture ground, texture,detail
build terrain ground
`position terrain Landscape(terrainid).id,Landscape(terrainid).X#,Landscape(terrainid).Y#,Landscape(terrainid).Z#
set text font "MS Gothic"
set text size 10
set text to bold
EndFunction
FUNCTION Progress(t$,prog#)
if prog#>100.0 then prog#=100.0
prog_x=(screen width()/2)-128
prog_y=(screen height()/2)
ink rgb(255,255,255),0
center text prog_x+128,prog_y-16,t$
ink rgb(16,16,16),0
box prog_x-1,prog_y-1,prog_x+257,prog_y+17
ink rgb(255,16,16),0
box prog_x-1,prog_y-1,prog_x+1+(prog#*256),prog_y+17
sync
ENDFUNCTION
function round(n#,r)
n#= n#/r
n= int(n#+n#)-int(n#)
n= n*r
endfunction n
function load_images(id1,id2,id3)
load image "tube8.png", id1
load image "circle.png", id2
load image "circle.png", id3
endfunction
function rgbalpha(r,g,b,a)
c = (a and 0xff) << 24 or ((r and 0xff) << 16) or ((g and 0xff) << 8) or (b and 0xff)
endfunction c
function CreateBar(theobj,twodorthreed,posx=0,posy=0,id,x,y,width,height,P#,c1,c2,max#)
if bitmap exist(id)=0
CREATE BITMAP id,width,height
endif
set current bitmap id
P# = P#/max#
if P#<0.0 then P#=0.0
rem gradient bar
seg = width / 3
box x, y, x+seg, y+height, c2,c1,c2,c1
box x+seg, y, x+seg+seg, y+height, c2,c1,c2,c1
box x+seg+seg, y, x+width, y+height, c2,c1,c2,c1
` box x, y, x+seg, y+height, rgbalpha(255,0,0,255),rgbalpha(255,0,0,255),rgbalpha(170,85,0,255),rgbalpha(170,85,0,255)
` box x+seg, y, x+seg+seg, y+height, rgbalpha(170,85,0,255),rgbalpha(170,85,0,255),rgbalpha(85,170,0,255),rgbalpha(85,170,0,255)
` box x+seg+seg, y, x+width, y+height, rgbalpha(85,170,0,255),rgbalpha(85,170,0,255),rgbalpha(0,255,0,255),rgbalpha(0,255,0,255)
` rem empty bit
` ink rgb(92,92,92),0
` box x+width*P#, y, x+width, y+height
rem highlight
box x, y, x+width, y+height*0.5, c2,c1,c2,c1
ink rgb(255,255,255),0
center text width/2,0,getnumber(int(P#*max#))+"/"+getnumber(int(max#))
if twodorthreed=0
GET IMAGE id,0,0,width,height,1
set current bitmap 0
paste image id,posx,posy
else
GET IMAGE id,0,0,width,height,1
set current bitmap 0
if object exist(obj)
texture object obj,id
else
exitfunction
endif
endif
endfunction
function getnumber(num)
n$=str$(num)
if num>999
n=num/1000
if n>999
m=n/1000
leng=len(str$(m))
re$=mid$(n$,leng+1)+mid$(n$,leng+2)
re$=mid$(n$,2)+mid$(n$,3)
r#=val(re$)
if r#>0.0
re$="."+re$
else
re$=""
endif
s$=str$(m)+re$+"M"
else
leng=len(str$(n))
re$=mid$(n$,leng+1)+mid$(n$,leng+2)
r#=val(re$)
if r#>0.0
re$="."+re$
else
re$=""
endif
s$=str$(n)+re$+"K"
endif
else
s$=str$(num)
endif
endfunction s$
function glue_object_to_object(a,b)
`get start and end point offsets
`start point
EZro_ObjFindOffsetFromPoint b, object position x(a),object position y(a),object position z(a)
x1#=EZro_GetOffsetX()
y1#=EZro_GetOffsetY()
z1#=EZro_GetOffsetZ()
`end point
move object a, 1
EZro_ObjFindOffsetFromPoint b, object position x(a),object position y(a),object position z(a)
x2#=EZro_GetOffsetX()
y2#=EZro_GetOffsetY()
z2#=EZro_GetOffsetZ()
`position child
position object a, x1#,y1#,z1#
`point at end point
point object a, x2#,y2#,z2#
`glue to main limb
glue object to limb a, b, 0
endfunction
function GetDist(camon,cam,myobj1,myobj2)
select camon
case 0
if myobj1<>0 and myobj2<>0
x1#=Object Position X(myobj2)
y1#=Object Position Y(myobj2)
z1#=Object Position Z(myobj2)
x2#=Object Position X(myobj1)
y2#=Object Position Y(myobj1)
z2#=Object Position Z(myobj1)
endif
endcase
case 1
if myobj1<>0
x1#=Camera Position X(cam)
y1#=Camera Position Y(cam)
z1#=Camera Position Z(cam)
x2#=Object Position X(myobj1)
y2#=Object Position Y(myobj1)
z2#=Object Position Z(myobj1)
endif
endcase
endselect
dist# = Dist(x1#,x2#,y1#,y2#,z1#,z2#)
endfunction dist#
Function Dist(x1#,x2#,y1#,y2#,z1#,z2#)
Set Vector3 1,x1#-x2#,y1#-y2#,z1#-z2#
rdist#=Length Vector3(1)
EndFunction rdist#
I attached the media and exe.
thanks!
CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/