Cannon

From Custom Mario Kart
Jump to navigation Jump to search

This page is a part of the Custom Track Tutorial. Back to the main tutorial page.

Introduction

Cannons are triggers that make your vehicle fly any distance in any direction, to any location of the track. They are present in every Mario Kart game except for the SNES and GBA editions. In Mario Kart Wii they appear in DK Summit, Maple Treeway, Rainbow Road, N64 DK's Jungle Parkway, and GCN DK Mountain. They also appear in a variety of custom tracks; the one with the biggest number of them is Cannon Castle.

Overview

Cannon of N64 DK's Jungle Parkway. You can see the cannon trigger (magenta wall) and the landing zone (magenta cuboid). The picture is exported by »wkmpt DRAW --draw kcl,obj,cnpt«.

Cannons are composed of three different parts:

  • the KCL trigger location
  • the KMP destination point
  • the optional object used to represent the cannon as seen in-game.

The three must be linked properly for the cannon to work.

KCL Trigger Location

Now, you'll need to set up a KCL collision flag to refer to each destination point. This means that once this location is touched in the KCL, it will activate your cannon. For each cannon your track has, you need one KCL polygon that is the trigger. This is probably the most exhausting part of creating a cannon, since you need to place your triggers in the KCL model, and a new KCL has to be generated for every change on the trigger areas. More about these KCL locations is explained in the Solidity tutorial. Once this KCL area is touched, the cannon activates and you are taken to the destination point. The KCL flag used in those polygons is 0x11 (cannon trigger). It is recommended that the cannon triggers are squares that cover the entire end of the road, but any shape can be used. And design the cannon triggers as a wall, so that a jump can't miss the trigger.

Multiple Cannons

For tracks with multiple cannons, you have to set KCL flag variants. Each cannon point in the KMP has a set ID, starting with 000 for the first point, 001 for the second, etc. The KCL polygon variant must be matched with this KMP ID. There's no need to worry about this if your track has only one cannon. Since KCL variants are a 3-bit integer, only a maximum of 8 cannons is possible in any track (variants 0 to 7). See the KCL Flag page for more information.

Object (Optional)

In some courses, a Launch Star (Rainbow Road) or a DK Barrel (other courses) is used to represent a cannon. These objects are not needed for the cannon to actually work, and are there just for the sights. Place them in the location of the cannon trigger. It does not need to be very precise, but you can experiment with the object's location. If your base track does not have a cannon object, you can learn how to port one in the Porting Objects section of this tutorial.

Setting Up the Location of the KMP Destination Point

This is simple; just place the point in the location where you want the cannon to drop you off at.

(Comically?) determining the angle of the Rainbow Road cannon with a protractor on the screen (well, it's faster than downloading a program just for that)

Sometimes, it is also needed to set up rotation values for each KMP cannon point. If the cannon is following the track's map either north or south (in the X-axis) there is no need for any cannon point rotation. If there is any angle other than 0º or 180º made between the cannon trigger and the destination point, this angle must be set in the Y angle value. You can use KMP Modifier, or KMP Cloud to edit the Y-angle. You can use a protractor to measure the angle, try to make an educated guess or calculate the angle based on the position of the cannon triggers and destination points.

Calculate the Y Rotation

You can calculate the Y rotation by using the mathematical atan function. If POS is the cannon position and DEST the cannon destination, do the following calculations. You can get POS and DEST with any KMP tool (perhaps moving temporary a point to the cannon trigger position).

// first: get the distance for the X and Z-axis:
dx = DEST.x - POS.x
dz = DEST.z - POS.z

// If function atan2() is available:
y_rotation = atan2(dx,dz)

// Alternatively you can use the base atan() function,
// but you must determine the sign by yourself:
if ( dz == 0 )
   y_rotation =  90 (or 'π/2' if calculating in rad)
else
   y_rotation = atan(dx/dz)

// If the result is in radiant, 
// multiply it by (180.0/π) to get degree.
y_rotation_degree = y_rotation_rad * 180.0 / π

In Wiimms SZS Tools you can simply replace the y-rotation by the function call: yDir(POS,DEST). Or you can use the command line:

wszst calc "yDir(v(POS_x,POS_z),v(DEST_x,DEST_z))"

Replace the 4 POS_* and DEST_* values by the coordinates of your model. The height (y-coordinate) is not needed.

X and Z Rotation

Setting up X and Z angles is usually not needed, since cannons are usually straight lines leading you upwards and a certain distance from the trigger. The X or Z rotation can be used to turn the vehicles in the landing zone. This needs a complex calculation.

Cannon Properties

Properties of the cannons
index Speed Height Deceleration
Factor
End
Deceleration
0 500.0 0.0 6000.0 -1.0
1 500.0 5000.0 6000.0 -1.0
2 120.0 2000.0 1000.0 45.0
Notes
  • Each cannon has 4 floating point properties P1..P4. Nintendo uses only integral number without fraction for all settings. As usual, all 4 regions share the same values.
  • Cannon -1 and any negative index is the same as cannon 0 (minimum clamp).
  • Cannons ≥3 do not exist. If using it, the property pointer points to the next data section, which is a class vtable. The result will be undefined.
  • Speed is the number of units each frame. For example, 500.0 means 500 units each frame or 60*500=30000 units each second.
  • Height defines a point above the middle of the direct connection, where the player goes through. This is the value of curved.
  • Deceleration Factor determines how much the player decelerates each frame on the cannon. A bigger value means a bigger deceleration, and hence the cannon progresses slower.
  • End Deceleration is the final deceleration value, once the cannon reaches its end. If ≤0, there is no deceleration. A bigger value means a longer stop time when reaching the end of the cannon.
  • LE-CODE supports alternative properties for any number of cannon types on track base. See LE-CODE Track FAQ for details.


Extra Info

  • The first cannon (whether there is one or more) should use 000 as a KMP point ID and KCL flag variant.
  • If you are using multiple cannons, each cannon ID must use a number starting at 000 and progressing as 001, 002, 003 etc on each additional cannon. The maximum is 007.
  • The effect settings of the KMP cannon point set the type of the cannon:
    • 0x0000 - fast, straight line (most normal cannons; used in Maple Treeway and Rainbow Road), Same as 0xFFFF (-1).
    • 0x0001 - curved (used in DK Summit and GCN DK Mountain)
    • 0x0002 - similar to above (used in N64 DK's Jungle Parkway)
    • 0x0003 - Invalid! Random effects, because the game reads data behind the cannon table. Do not use it!
  • The sound of the cannon is sometimes slot-specific (like on N64 DK's Jungle Parkway), sometimes generated by the cannon object (like on Maple Treeway) and sometimes both (like on Rainbow Road). It might also be generated by a normal KCL-based sound trigger.