Yes. That is just what I wanted!
I see that you did that with a limb.
But I don't see how it works.
Edit: For some reason when I try this code out in my game, the ship will not turn. I have no ideal why it will not work.
Edit2: Got it, forgot to change a couple of object numbers! Noob!
Rem Project: Terran Space Navy
Rem Created: Friday, August 13, 2010
Rem ***** Main Source File *****
Sync On: Sync Rate 60: Autocam Off
sync
center text screen width()/2,screen height()/2,"LOADING"
sync
Global Dim ObjTaken(0) as Boolean
ScreenWidth#=SCREEN WIDTH()
ScreenHeight#=SCREEN HEIGHT()
speed# =0
Speedincrease# = 0.005
maxspeed# =1.5
Engine as boolean : Engine =1
SpdBrkt =0
GoSub Initialize
GoSub init_Keys
GoSub Load_Images
GoSub Load_Objects
Do
GoSub Move_Target
GoSub Move_Player
GoSub Mouse_Pick_Shoot
GoSub Camera_Control
GoSub Information
GoSub Late_Loopers
cometSYNC(60,500)
LOOP
``Subroutines
Initialize:
Set Camera Range 0, 1,999999
make camera 2
Set Camera Aspect 2,1
Set Camera Range 2,1,999999
make memblock 1,16900 `image for camera 2
make image from memblock 2,1
`Cam-Output to image 2
set camera to image 2,2,256,256
`Position the Sprite (Output Screen) right/top
sprite 2,768,0,2
Set Ambient Light 20
Position Mouse 400,400
Return
init_Keys:
global dim NBS(255) as integer
global dim JNBS(20) as integer
return
Load_Images:
Set Image ColorKey 0,0,0
Load Image "Res\Upper_panel.bmp",10
sprite 10,0,0,10
Load Image "Res\Laser.bmp",11
Load Image "Res\Grid.tga", 12
Return
Move_Target:
nDist# = sqrt(object_distance(201,204))
if nDist# > .5
Point Object 201,Object Position x(204),Object Position y(204),Object Position z(204)
move Object 201,0.5
nDist# = sqrt(object_distance(201,204))
endif
If nDist# < .5 Then Position Object 204, 200 + rnd(2000)- 1000,0,200 + rnd(2000)- 1000
Return
Move_Player:
Move object 200,speed#
IF KEYSTATE (2)= 1 AND Engine =1 Then SpdBrkt = 1:oldSpdBrkt=SpdBrkt `1
IF KEYSTATE (3)= 1 AND Engine =1 Then SpdBrkt = 2:oldSpdBrkt=SpdBrkt `2
IF KEYSTATE (4)= 1 AND Engine =1 Then SpdBrkt = 3:oldSpdBrkt=SpdBrkt `3
IF KEYSTATE (5)= 1 AND Engine =1 Then SpdBrkt = 4:oldSpdBrkt=SpdBrkt `4
if keystate(41)= 1 AND Engine =1 Then SpdBrkt = 5 `zero key
IF SpdBrkt = 1
if speed# > 0.25 then speed# = speed# - speedincrease#
if speed# < 0.25 Then Speed# = Speed# + speedincrease#
ENDIF
IF SpdBrkt = 2
if speed# > 0.50 then speed# = speed# - speedincrease#
if speed# < 0.50 Then Speed# = Speed# + speedincrease#
ENDIF
IF SpdBrkt = 3
if speed# >= 0.75 then speed# = speed# - speedincrease#
if speed# =< 0.75 Then Speed# = Speed# + speedincrease#
ENDIF
IF SpdBrkt = 4
if speed# >= 1.0 then speed# = speed# - speedincrease#
if speed# =< 1.0 Then Speed# = Speed# + speedincrease#
ENDIF
IF SpdBrkt = 5
if speed# >= 0.0 then speed# = speed# - speedincrease#
if speed# =< 0.0 Then Speed# = 0
ENDIF
if keystate(13)=1 then SpdBrkt =null
if keystate(13)=1 Then speed#=speed#+speedincrease#
if keystate(12)=1 then SpdBrkt =null
if keystate(12)=1 then speed#=speed#-speedincrease#
`Check if the the turning switch is on
if Turning=1
` Reset speed to old speed
SpdBrkt=oldSpdBrkt
` Turn off turning switch
Turning=0
endif
` a
if keystate(30)=1
yrotate object 200,wrapvalue(object angle y(1) - 0.4)
if tilt#<45.0 then tilt#=tilt#+0.4
rotate limb 200,0,0,0,tilt#
` Save the old speed
oldSpdBrkt=SpdBrkt
` Change the speed
SpdBrkt=5
` Turn on the Turning switch
Turning=1
endif
` d
if keystate(32)=1 and Turning=0
yrotate object 200,wrapvalue(object angle y(1) + 0.4)
if tilt#>-45.0 then tilt#=tilt#-0.4
rotate limb 200,0,0,0,tilt#
` Save the old speed
oldSpdBrkt=SpdBrkt
` Change the speed
SpdBrkt=5
` Turn on the Turning switch
Turning=1
endif
if keystate(30)=0 and keystate(32)=0
if tilt#<0.0 then tilt#=tilt#+0.4
if tilt#>0.0 then tilt#=tilt#-0.4
rotate limb 200,0,0,0,tilt#
endif
Return
Mouse_Pick_Shoot:
Set Current Camera 0
If mouseclick() = 1 and ShipD# < 100
If pick object(mousex () ,mousey (), 201,201)>0
`Fire weapon
setPlaneLine(1,Object Position X (200),Object Position Y (200),Object Position Z (200),Object Position X (201),Object Position Y (201),Object Position Z (201),2.5)
EndIf
EndIf
return
Camera_Control:
`Record the camera's position before you put it where you want it.
WhereItWasBeforeX#=camera position x()
WhereItWasBeforeY#=camera position y()
WhereItWasBeforeZ#=camera position z()
`Record the camera's angle before you put it where you want it. The Wrapvalue() command just keeps the angle measure between 0 and 360 degrees. For example, 365 degrees would become 5 degrees, since they're both the same thing.
WhereItWasBeforeAngleX#=Wrapvalue( camera angle x() )
WhereItWasBeforeAngleY#=Wrapvalue( camera angle y() )
WhereItWasBeforeAngleZ#=Wrapvalue( camera angle z() )
`Put the camera where you want it to be.
position camera object POSITION X(200), OBJECT POSITION Y(200), OBJECT POSITION Z(200)
SET CAMERA TO OBJECT ORIENTATION 200
move camera 0,-15
xrotate camera camera angle x()-90
move camera 0,4
xrotate camera camera angle x()+90
`Record this new position (where you WANT the camera to be) in some variables
WhereItShouldBeX#=camera position x()
WhereItShouldBeY#=camera position y()
WhereItShouldBeZ#=camera position z()
`Record the new angle in some variables
WhereItShouldBeAngleX#=Wrapvalue( camera angle x() )
WhereItShouldBeAngleY#=Wrapvalue( camera angle y() )
WhereItShouldBeAngleZ#=Wrapvalue( camera angle z() )
`Smoothly transition the camera from where it was before to where you want it to be. Record this "transitioned value" in new variables.
Smoothness#=10.0 `This is how much smoothness you want. 1 is no smoothness and higher numbers give you more and more smoothness.
`(The curvevalue command basically moves a value from one value to another within a certain number of steps. The more steps, the longer it takes for the value to get where you want it to be.
cx#=Curvevalue(WhereItShouldBeX#,WhereItWasBeforeX#,Smoothness#)
cy#=Curvevalue(WhereItShouldBeY#,WhereItWasBeforeY#,Smoothness#)
cz#=Curvevalue(WhereItShouldBeZ#,WhereItWasBeforeZ#,Smoothness#)
`Smoothly transition the camera's angle. I will use the Curveangle command here because it's better for angles than Curvevalue.
cax#=Curveangle(WhereItShouldBeAngleX#,WhereItWasBeforeAngleX#,Smoothness#)
cay#=Curveangle(WhereItShouldBeAngleY#,WhereItWasBeforeAngleY#,Smoothness#)
caz#=Curveangle(WhereItShouldBeAngleZ#,WhereItWasBeforeAngleZ#,Smoothness#)
position camera 2, Object Position x (203),Object Position y (203)+3,Object Position z (203)
Point Camera 2, Object Position x (201),Object Position y (201),Object Position z (201)
SET CAMERA TO OBJECT ORIENTATION 2,203
move camera 2,-12
`Finally, put the camera in its place and rotate it based on the smooth transitions above.
position camera cx#,cy#,cz#
rotate camera cax#,cay#,caz#
Return
Information:
`start printing at top of screen
set cursor 0, 40
print "FPS = " + str$ ( screen fps ( ) )
Print "Current Ship position"
print "x = " + str$ ( floor (Object position x (200)))
print "y = " + str$ ( floor (Object position y (200)))
print "z = " + str$ ( floor (Object position z (200)))
print "Polygon count = " + str$ (statistic(1))
print "Speed = " + str$ ( speed# )
print "x Angle " + str$ (Object angle x (200))
print "y Angle " + str$ (Object angle y (200))
print "z Angle " + str$ (Object angle z (200))
print "Distance to Ship " + str$ (floor(ShipD#))
Print "Distance to Planet " + str$ (floor(PlntD#))
print "EnemyHitPoints " + str$ (EnemyHP)
return
Load_Objects:
Load Object "Res\Star_Sphere.x",199
set object light 199, 1
set object texture 199, 3, 1
Turn Object left 199, 90
`Position Object 199,0,0,0
`scale object 199, 50, 50, 50
Load Object "Res\Corvette.DBO",200
set object light 200, 1
set object texture 200, 3, 0
position object 200, 520, 0, 520
`SC_setupComplexObject 200 , 0 , 2
`SC_setObjectCollisionOn 200
`SC_allowObjectScaling 200
Scale Object 200,5,5,5
`SC_updateObject 200
Load Object "Res\EDF_Fletcher.x",201
set object light 201, 1
set object texture 201, 3, 0
position object 201, 500, 0, 500
`SC_setupComplexObject 201 , 0 , 2
`SC_setObjectCollisionOn 201
`SC_allowObjectScaling 201
Scale Object 201,10,10,10
`SC_updateObject 201
Load Object "Res\Earth.x",202
set object light 202, 1
set object texture 202, 3, 0
position object 202, 0, 0, 0
`SC_setupComplexObject 202 , 0 , 2
`SC_setObjectCollisionOn 202
`SC_allowObjectScaling 202
`SC_updateObject 202
Make object sphere 203,0.25 ` for camera 1 to use for orientation
Position Object 203,Object Position x (201),Object Position y (201),Object Position z (201)
Hide Object 203
Make Object Cube 204,10 `for fletcher to chase
Position Object 204, rnd(2000)+ 200 ,0,rnd(2000)+ 200
Make object plane 205,2500,2500
Position Object 205, 0,0,0
xrotate object 205,90
Set object transparency 205, 6
Set Alpha Mapping on 205, 99
Texture Object 205,12
make object plain 1, 100,100
yrotate object 1, 90
fix object pivot 1
Set Object Transparency 1,6
Set Alpha Mapping On 1,99
Texture Object 1,11
make object plain 2, 100,100
rotate object 2, 90,90,0
fix object pivot 2
Set Object Transparency 2,6
Set Alpha Mapping On 2,99
Texture Object 2,11
Return
Late_Loopers:
ShipD# = sqrt (object_distance(200,201))
PlntD# = sqrt (object_distance (200,202))
if speed#>maxspeed# Then Speed# = maxspeed#
if speed# < 0 Then speed#=0
Position Object 199,Object Position x (200),Object Position y (200),Object Position z (200)
Position Object 203,Object Position x (200),Object Position y (200),Object Position z (200)
Point object 203,Object Position x (201),Object Position y (201),Object Position z (201)
Turn Object Right 202,.025
Return
``Functions
function object_distance(a,b) `Get distance
d#=(object position x(a)-object position x(b))^2+(object position y(a)-object position y(b))^2+(object position z(a)-object position z(b))^2
ENDFUNCTION d#
Function FreeObject( ) ` Free Object
` Add to array
Array Insert At Bottom ObjTaken()
Obj = Array Count( ObjTaken() )
` If object Obj doesnt exist, and isnt reserved..
If ( (Object Exist( Obj ) = 0) && (ObjTaken(Obj) = 0) )
` Reserve
ObjTaken( Obj ) = 1
` Return object
ExitFunction Obj
Endif
EndFunction 0
function cometSYNC(syncrate,update)
syncrate=syncrate/(1000/update):ssync=syncrate:inc syncrate,offset:time=timer():time_elapsed=time-oldtimer:inc cloop:if time_elapsed>=update:lastloopsmissed=loopsmissed:loopsmissed=((syncrate-cloop)+lastloopsmissed)/2:result=cloop
cloop=1:oldtimer=time:if loopsmissed<1:skip#=0:incskip#=0:else:x#=syncrate:y#=loopsmissed:skip#=x#/y#:incskip#=skip#:endif:inc offset,(ssync-result):result=result*(1000/update):endif:if int(skip#)=cloop then inc skip#,incskip# else sync
endfunction result
function KeyRel(but)
Retn = 0
if keystate(but) = 1
NBS(but) = 1
else
IF NBS(but) = 1 then retn = 1
NBS(but) = 0
endif
endfunction retn
function KeyPress(but)
Retn = 0
if keystate(but) = 1
IF NBS(but) = 0 then retn = 1
NBS(but) = 1
else
NBS(but) = 0
endif
endfunction retn
Function JoyRel(but)
Retn = 0
if Joystick fire x(but) = 1
JNBS(but) = 1
else
IF JNBS(but) = 1 then retn = 1
JNBS(but) = 0
endif
EndFunction Retn
function setPlaneLine(obj,x1,y1,z1,x2,y2,z2, thickness)
dx = (x2-x1)
dy = (y2-y1)
dz = (z2-z1)
x3 = x1 + dx/2
y3 = y1 + dy/2
z3 = z1 + dz/2
d = sqrt(dx*dx + dy*dy + dz*dz)
position object obj, x3,y3,z3
point object obj, x2,y2,z2
scale object obj, d, thickness,25
position object obj+1, x3,y3,z3
point object obj+1, x2,y2,z2
scale object obj+1, d, thickness,25
endfunction
Thank you Scorpyo
put this in your code snippets, code lang = dbp