Writing Custom Platform Types

With a little coding knowledge you can easily create your own platform types by extending the existing Platform types. The API has several key elements to consider. Full API doc is available online here.

 

Tip: If you don't have coding skills you can always contact JNA Mobile and ask us to build your custom platforms. Although we can't guarantee a solution we are always eager to help and extend the capabilities of Platformer PRO.

 

Collisions

The basic task of a custom platform is to respond to collisions. The collision routine is broken in to three functions:

virtual public bool Collide(PlatformCollisionArgs args)

The entry point for the characters interaction with the platform. Returns true if the character should be parented to the platform. By default it does the following:

virtual public bool Collide(PlatformCollisionArgs args) {
  BaseCollide(args);
  return CustomCollide(args);
}

For most Platforms you will not need to change this.

protected void BaseCollide(PlatformCollisionArgs args)

The built-in handling of collisions. Cannot be overridden but if you don't want default behaviours you can override the Collide() function so that this is not called.

virtual protected bool CustomCollide(PlatformCollisionArgs args)

Most of your custom platform code should go here. By default the value that this function returns will also be returned by Collide().

Typically your custom collision will check the type of collider that is hitting the platform and if the condition is met it will take some action. For example a moving platform will generally check if the characters FOOT is hitting the platform and if so will parent the character:

override protected bool CustomCollide(PlatformCollisionArgs args)
{
  if (args.RaycastCollider.RaycastType == RaycastType.FOOT)
  {
    return true;
  }
  return false;
}

 

The PlatformCollisionArgs (see API doc) also include a Character reference and details of the penetration of the collider. You can for example use these to interact with the character. For example to freeze the character in the air when they move through a platform:

override protected bool CustomCollide(PlatformCollisionArgs args)
{
  args.Character.SetVelocityY(0);
  return false;
}

 

Skip Movement

The skip movement function:

virtual public bool SkipMovement(Character character, Movement movement)

is called by the Character each frame and allows a Platform to disallow certain movement types. It is passed the movement type being evaluation by Character.TransitionMovement and if the function returns true that movement will not be used.

For example a sticky substance which stops you jumping could do the following:

override public bool SkipMovement(Character character, Movement movement)
{
  if (movement is AirMovement) {
    return true;
  }
  return false;
}



Note: The default air and ground movements cannot be skipped.

Parent and Unparent


When a character is parented to the platform the Parent() function is called. You can use this to respond to the parenting. For example you may start a timer which will cause the character to die if they don't unparent in time:

override public void Parent()
{
  StartCoroutine(DieInFiveSeconds());
} 

 

Similarly when a character is unparented from a Platform the UnParent() function is called. You can use this to respond to the unparenting. For example you may stop the timer from the above example:

override public void UnParent()
{
  StopCoroutine(DieInFiveSeconds);
}

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk