How to Make Models Pitch: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Added a Tut from Dr. Kylstien code.
 
grammar (spacing, commas, colons, terminology, capitalization, et cetera), pre tag replacement because it disables formatting (like bold)
 
(One intermediate revision by one other user not shown)
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 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]].


The following code will allow actors that call the state to pitch and roll if they are placed or move onto a sloped surface. 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.


Note: This code should be placed at the top of GAME.CON or at least called first before any actors call the state.
The following code will allow actors that call the state to pitch and roll if they are placed or move onto a sloped surface.  


First off, we will need the following gamevars
Note: This code should be placed at the top of GAME.CON or at least written first before any actors call the state.


<pre>
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
</pre>


Then we need to define two things.
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


<pre>
Then, we need to define two things:
define TILT_SPEED 32
define TILT_MAX 128 // This value maybe edited if more slope is required.
</pre>


Then the code its self.
define TILT_SPEED 32
define TILT_MAX 128 // This value may be edited if more sloping is required.


<pre>
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
state pitchroll {
subvarvar z b
iffloordistl 8
shiftvarr z 3
{
// get z behind? actor
// cap amount of pitch, Duke looks silly leaning out so far
getactor[THISACTOR].x x
ifvarg z TILT_MAX setvar z TILT_MAX
getactor[THISACTOR].y y
setvar a TILT_MAX mulvar a -1
getactor[THISACTOR].z z
ifvarvarl z a setvarvar z a
getactor[THISACTOR].ang angle
getactor[THISACTOR].clipdist a
// gradually adjust pitch to avoid jerkily snapping to the slope
mulvar a -1 addvarvar a x
getactor[THISACTOR].pitch a
rotatepoint x y a y angle x y
ifvarvarg a z {
updatesectorz x y z SECTOR
subvar a TILT_SPEED
ifvarn SECTOR -1 { //make sure calculated point is in a SECTOR
setactor[THISACTOR].pitch a
getflorzofslope SECTOR x y b
} else ifvarvarg a z {
} else {
setactor[THISACTOR].pitch z
getactor[THISACTOR].z b
}
}
ifvarvarl a z {
// get z in front? of actor
addvar a TILT_SPEED
getactor[THISACTOR].x x
setactor[THISACTOR].pitch a
getactor[THISACTOR].y y
} else ifvarvarl a z {
getactor[THISACTOR].clipdist a
setactor[THISACTOR].pitch z
addvarvar a x
}
rotatepoint x y a y angle x y
updatesectorz x y z SECTOR
// get z right? of actor
ifvarn SECTOR -1 {
getactor[THISACTOR].x x
getflorzofslope SECTOR x y z
getactor[THISACTOR].y y
} else {
getactor[THISACTOR].z z
getactor[THISACTOR].z z
getactor[THISACTOR].ang angle
}
getactor[THISACTOR].clipdist a
addvarvar a y
// get pitch amount
rotatepoint x y x a angle x y
subvarvar z b
updatesectorz x y z SECTOR
shiftvarr z 3
ifvarn SECTOR -1 {
getflorzofslope SECTOR x y b
// cap amount of pitch, Duke looks silly leaning out so far
} else {
ifvarg z TILT_MAX setvar z TILT_MAX
getactor[THISACTOR].z b
setvar a TILT_MAX mulvar a -1
}
ifvarvarl z a setvarvar z a
// get left? of actor
// gradually adjust pitch to avoid jerkily snapping to the slope
getactor[THISACTOR].x x
getactor[THISACTOR].pitch a
getactor[THISACTOR].y y
ifvarvarg a z {
getactor[THISACTOR].clipdist a
subvar a TILT_SPEED
mulvar a -1 addvarvar a y
setactor[THISACTOR].pitch a
rotatepoint x y x a angle x y
} else ifvarvarg a z {
updatesectorz x y z SECTOR
setactor[THISACTOR].pitch z
ifvarn SECTOR -1 {
}
getflorzofslope SECTOR x y z
ifvarvarl a z {
} else {
addvar a TILT_SPEED
getactor[THISACTOR].z z
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 roll 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 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
</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.
actor CHAINGUNSPRITE
<pre>
  fall
actor CHAINGUNSPRITE
  '''state pitchroll''' // This is where I have placed the state.
  fall
  ifmove RESPAWN_ACTOR_FLAG
  state pitchroll // This is where I have placed the state
    state respawnit
  ifmove RESPAWN_ACTOR_FLAG
  else
    state respawnit
    ifp pshrunk nullop
  else
    else
    ifp pshrunk nullop
      ifp palive
    else
        ifpdistl RETRIEVEDISTANCE
      ifp palive
          ifcount 6
        ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
          ifcount 6
      {
            ifcanseetarget
        ifgotweaponce 0
      {
          break
        ifgotweaponce 0
          break
        addweapon CHAINGUN_WEAPON 50
 
        quote 54
        addweapon CHAINGUN_WEAPON 50
        ifspawnedby CHAINGUNSPRITE
        quote 54
          state getweaponcode
        ifspawnedby CHAINGUNSPRITE
        else
          state getweaponcode
          state quikweaponget
        else
      }
          state quikweaponget
enda
      }
enda
</pre>

Latest revision as of 08: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