How to Make Models Pitch
As we know the build engine has limits of that it can not pitch 2D sprites (think of a picture hanging on a wall crooked) but we can exploit this by using 3D models plus the structure members Pitch and Roll
It is best to use the code as a state so that every actor is not using it, other wise it could have a "serious" impact on your frame rate. (not to mention that certain actors would just look bad using this code)
The following code will allow actors that call the state to pitch and roll if they are placed or move onto a sloped surface.
Note: This code should be placed at the top of GAME.CON or at least called first before any actors call the state.
First off, we will need the following gamevars
gamevar a 0 0 gamevar b 0 0 gamevar x 0 0 gamevar y 0 0 gamevar z 0 0 gamevar angle 0 0 gamevar SECTOR 0 0
Then we need to define two things.
define TILT_SPEED 32 define TILT_MAX 128 // This value maybe edited if more slope is required.
Then the code its self.
state pitchroll {
iffloordistl 8
{
// get z behind? actor
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
getactor[THISACTOR].ang angle
getactor[THISACTOR].clipdist a
mulvar a -1 addvarvar a x
rotatepoint x y a y angle x y
updatesectorz x y z SECTOR
ifvarn SECTOR -1 { //make sure calculated point is in a SECTOR
getflorzofslope SECTOR x y b
} else {
getactor[THISACTOR].z b
}
// get z in front? of actor
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].clipdist a
addvarvar a x
rotatepoint x y a y angle x y
updatesectorz x y z SECTOR
ifvarn SECTOR -1 {
getflorzofslope SECTOR x y z
} else {
getactor[THISACTOR].z z
}
// get pitch amount
subvarvar z b
shiftvarr z 3
// cap amount of pitch, Duke looks silly leaning out so far
ifvarg z TILT_MAX setvar z TILT_MAX
setvar a TILT_MAX mulvar a -1
ifvarvarl z a setvarvar z a
// gradually adjust pitch to avoid jerkily snapping to the slope
getactor[THISACTOR].pitch a
ifvarvarg a z {
subvar a TILT_SPEED
setactor[THISACTOR].pitch a
} else ifvarvarg a z {
setactor[THISACTOR].pitch z
}
ifvarvarl a z {
addvar a TILT_SPEED
setactor[THISACTOR].pitch a
} else ifvarvarl a z {
setactor[THISACTOR].pitch z
}
// get z right? of actor
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
getactor[THISACTOR].ang angle
getactor[THISACTOR].clipdist a
addvarvar a y
rotatepoint x y x a angle x y
updatesectorz x y z SECTOR
ifvarn SECTOR -1 {
getflorzofslope SECTOR x y b
} else {
getactor[THISACTOR].z b
}
// get left? of actor
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].clipdist a
mulvar a -1 addvarvar a y
rotatepoint x y x a angle x y
updatesectorz x y z SECTOR
ifvarn SECTOR -1 {
getflorzofslope SECTOR x y z
} else {
getactor[THISACTOR].z z
}
// get roll amount
subvarvar z b
shiftvarr z 3
// cap amount of roll
ifvarg z TILT_MAX setvar z TILT_MAX
setvar a TILT_MAX mulvar a -1
ifvarvarl z a setvarvar z a
// gradually adjust roll
getactor[THISACTOR].roll a
ifvarvarg a z {
subvar a TILT_SPEED
setactor[THISACTOR].roll a
} else ifvarvarg a z {
setactor[THISACTOR].roll z
}
ifvarvarl a z {
addvar a TILT_SPEED
setactor[THISACTOR].roll a
} else ifvarvarl a z {
setactor[THISACTOR].roll z
}
}
} ends
To make use of the state place the following line into any actor that will use it. For example I will use the chaingun.
actor CHAINGUNSPRITE
fall
state pitchroll // This is where I have placed the state
ifmove RESPAWN_ACTOR_FLAG
state respawnit
else
ifp pshrunk nullop
else
ifp palive
ifpdistl RETRIEVEDISTANCE
ifcount 6
ifcanseetarget
{
ifgotweaponce 0
break
addweapon CHAINGUN_WEAPON 50
quote 54
ifspawnedby CHAINGUNSPRITE
state getweaponcode
else
state quikweaponget
}
enda