How to Make Models Pitch: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
No edit summary
grammar (spacing, commas, colons, terminology, capitalization, et cetera), pre tag replacement because it disables formatting (like bold)
 
Line 1: Line 1:
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]]
As we know the BUILD Engine has limits, such as 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)
It is best to use the code as a state so that every actor is not using it, otherwise 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.  
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.
Note: This code should be placed at the top of GAME.CON or at least written first before any actors call the state.


First off, we will need the following gamevars
First off, we will need the following gamevars:


<pre>
gamevar a 0 0
gamevar a 0 0
gamevar b 0 0
gamevar b 0 0
gamevar x 0 0
gamevar x 0 0
gamevar y 0 0
gamevar y 0 0
gamevar z 0 0
gamevar z 0 0
gamevar angle 0 0
gamevar angle 0 0
gamevar SECTOR 0 0
gamevar SECTOR 0 0
</pre>


Then we need to define two things.
Then, we need to define two things:


<pre>
define TILT_SPEED 32
define TILT_SPEED 32
define TILT_MAX 128 // This value may be edited if more sloping is required.
define TILT_MAX 128 // This value maybe edited if more slope is required.
</pre>


Then the code its self.
Next, the code itself:


<pre>
state pitchroll {
state pitchroll {
iffloordistl 8
iffloordistl 8
{
{
// get z behind? actor
// get z behind? actor
getactor[THISACTOR].x x
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].y y
getactor[THISACTOR].z z
getactor[THISACTOR].z z
getactor[THISACTOR].ang angle
getactor[THISACTOR].ang angle
getactor[THISACTOR].clipdist a
getactor[THISACTOR].clipdist a
mulvar a -1 addvarvar a x
mulvar a -1 addvarvar a x
rotatepoint x y a y angle x y
rotatepoint x y a y angle x y
updatesectorz x y z SECTOR
updatesectorz x y z SECTOR
ifvarn SECTOR -1 { //make sure calculated point is in a SECTOR
ifvarn SECTOR -1 { //make sure calculated point is in a SECTOR
getflorzofslope SECTOR x y b
getflorzofslope SECTOR x y b
} else {
} else {
getactor[THISACTOR].z b
getactor[THISACTOR].z b
}
}
// get z in front? of actor
// get z in front? of actor
getactor[THISACTOR].x x
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].y y
getactor[THISACTOR].clipdist a
getactor[THISACTOR].clipdist a
addvarvar a x
addvarvar a x
rotatepoint x y a y angle x y
rotatepoint x y a y angle x y
updatesectorz x y z SECTOR
updatesectorz x y z SECTOR
ifvarn SECTOR -1 {
ifvarn SECTOR -1 {
getflorzofslope SECTOR x y z
getflorzofslope SECTOR x y z
} else {
} else {
getactor[THISACTOR].z z
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


// get pitch amount
Finally, to make use of the state, place the following line into any actor that will use it. For example, I will use the chaingun pickup.
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
actor CHAINGUNSPRITE
subvarvar z b
  fall
shiftvarr z 3
  '''state pitchroll''' // This is where I have placed the state.
  ifmove RESPAWN_ACTOR_FLAG
// cap amount of roll
    state respawnit
ifvarg z TILT_MAX setvar z TILT_MAX
  else
setvar a TILT_MAX mulvar a -1
    ifp pshrunk nullop
ifvarvarl z a setvarvar z a
    else
      ifp palive
// gradually adjust roll
        ifpdistl RETRIEVEDISTANCE
getactor[THISACTOR].roll a
          ifcount 6
ifvarvarg a z {
            ifcanseetarget
subvar a TILT_SPEED
      {
setactor[THISACTOR].roll a
        ifgotweaponce 0
} else ifvarvarg a z {
          break
setactor[THISACTOR].roll z
}
        addweapon CHAINGUN_WEAPON 50
ifvarvarl a z {
        quote 54
addvar a TILT_SPEED
        ifspawnedby CHAINGUNSPRITE
setactor[THISACTOR].roll a
          state getweaponcode
} else ifvarvarl a z {
        else
setactor[THISACTOR].roll z
          state quikweaponget
}
      }
}
enda
} ends
</pre>
 
To make use of the state place the following line into any actor that will use it. For example I will use the chaingun.
<pre>
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
</pre>

Latest revision as of 09:51, 21 February 2009

As we know the BUILD Engine has limits, such as 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, otherwise 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 written 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 may be edited if more sloping is required.

Next, the code itself:

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

Finally, to make use of the state, place the following line into any actor that will use it. For example, I will use the chaingun pickup.

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