Ahhh i noticed a potential bug in my grenade system...easily fixed though !
after the
global Gravity#=40.0
global Life#=10.0
global CurrentLife#=0.0
bit add a
remove the
` variable for making sure runs at the same speed regardless of framerate`
fps#=(1.0/screen fps())
from the move grenade routine and paste it in the main loop
eg:
`=====================`
` Main Loop `
`=====================`
Do
` variable for making sure runs at the same speed regardless of framerate`
fps#=(1.0/screen fps())
CamLook() : ` I havnt included a collision system for the player so you can look around but not move, this reduces
` the chance of confusion and also of any mistakes i might make while coding it !
if mouseclick()=1 then MakeGenade()
MoveGrenade()
sync
Loop
This fixes a possible erratic launch of the grenade, was bugging the hell out of me so im glad ive found it !
so my whole code i gave before look like this now
REM Project: grenade demo
REM Created: 22/05/2005 14:53:23
REM
REM ***** Main Source File *****
REM
`Mandatory Setup blah`
Cls
Sync on
autocam off
`Weird memblock thing to keep sparky's dll happy`
make memblock 1,1
delete memblock 1
hide mouse
`Load Level`
Load object "GrenLevel.x",1
scale object 1,1400,1400,1400
Set ambient light 40
setupobject 1,0,0
`Make grenade`
Make object sphere 2,3
`position "player"`
position camera 0,20,0
`Make Vector to store the object's speed`
null=Make vector3(1)
`Make a spare vector (used later to hold values temporarily)
null=make vector3(99)
`Make Value to store the gravity`
global Gravity#=40.0
global Life#=10.0
global CurrentLife#=0.0
global Fps#=0.0
`=====================`
` Main Loop `
`=====================`
Do
` variable for making sure runs at the same speed regardless of framerate`
fps#=(1.0/screen fps())
CamLook() : ` I havnt included a collision system for the player so you can look around but not move, this reduces
` the chance of confusion and also of any mistakes i might make while coding it !
if mouseclick()=1 then MakeGenade()
MoveGrenade()
sync
Loop
`=====================`
` Camera Commands `
`=====================`
Function CamLook()
cx#=camera angle x()
cy#=camera angle y()
cz#=camera angle z()
cy#=wrapvalue(cy#+mousemovex())
cx#=wrapvalue(cx#+mousemovey())
rotate camera cx#,cy#,0
endfunction
`======================`
` Grenade Handling `
`======================`
Function MakeGenade()
If object visible(2)=0
show object 2
position object 2,camera position x(),camera position y(),camera position z()
VectorToCamera(1)
scale vector3 1,1,60
CurrentLife#=Life#
endif
Endfunction
Function MoveGrenade()
if object visible(2)=1
`Reduce the life (time left until explosion)
CurrentLife#=(CurrentLife#-fps#)
`Add the gravity to the grenade speed, notice we multiply by fps# to keep the speed the same on all framerates
set vector3 1,x vector3(1),(y vector3(1)-(gravity#*fps#)),z vector3(1)
`Work out how far grenade is going to move`
movex#=(x vector3(1)*fps#)
movey#=(y vector3(1)*fps#)
movez#=(z vector3(1)*fps#)
`Current Grenade position
x#=object position x(2)
y#=object position y(2)
z#=object position z(2)
`Check for collision`
Obhit=intersectobject(0,0,x#,y#,z#,(x#+movex#),(y#+movey#),(z#+movez#),0)
if obhit>0
set vector3 99,GetCollisionNormalX(),GetCollisionNormalY(),GetCollisionNormalZ()
ReflectVector(1,99) :` if grenade has hit wall then relect the vector (makes the grenade bounce)
scale vector3 1,1,0.9 : `sets the ammount of energy lost by the bounce...try setting this above 1
`rework out how far grenade is going to move`
movex#=(x vector3(1)*fps#)
movey#=(y vector3(1)*fps#)
movez#=(z vector3(1)*fps#)
endif
position object 2,(x#+movex#),(y#+movey#),(z#+movez#)
if CurrentLife#<0.0 then hide object 2
endif
Endfunction
`=====================`
` Vector Commands `
`=====================`
Function VectorToCamera(vec)
oldx#=camera position x()
oldy#=camera position y()
oldz#=camera position z()
move camera 10.0
x#=camera position x()
y#=camera position y()
z#=camera position z()
move camera -10.0
set vector3 vec,(x#-oldx#),(y#-oldy#),(z#-oldz#)
normalize vector3 vec,vec
endfunction
Function ReflectVector(vector,normal)
dot#=dot product vector3(vector,normal)
dot#=(dot#*2.0)
multiply vector3 Normal,dot#
subtract vector3 vector,vector,Normal
endfunction
I hope these changes arnt too much bother too implement ?
Enjoy !