MegaShapes Walk Loft


The Walk Loft component allows you to easily position objects directly onto a loft surface. You can use this to position your main game object or just to populate the surface with objects. If the underlying surface changes at all the objects will remain attached to the surface. You have control over the orientation and offsets of the object as well. To use the system you only need add the Walk Loft component to your game object and pick the Loft Object and the layer to walk on and then use the alpha values to position the object on the surface. You have a choice between Alpha mode or distance mode to position your objects.

Walk Loft Params

Mode

Set to use either Alpha mode or Distance mode, Alpha mode uses a value between 0 and 1 to locate the object along the surface, the distance mode will use a distance value which may be more useful if you are controlling the object etc.

Alpha

How far along the surface the object will appear, 0 is the very start 1 is the very end.

Distance

How far along the surface the object will appear.

Cross Alpha

The position across the surface, 0 will be the very left edge and 1 the very right edge.

Surface

The Loft object to attach the object to.

Layer

When a Loft Object is selected the list of available surface layers you can attach the object to will appear in the drop down box, pick the layer you want.

Delay

How quickly the object aligns its up to the surface up, a value of 0 will snap instantly to match the surface up, the higher the value the more smoothly the object will re align to the surface.

Offset

An offset value to add in the x y and z directions, you can use this if your pivot point isnt quite in the right place or if you want to add in a local offset say in the Y direction for jumping. Note you can always attach your object to a dummy parent object and then use the walk loft on the parent, then you can use the local transforms of your main object to reposition, scale etc.

Tangent

This is how far ahead the system looks when it calculates up values etc, smaller values are more accurate.

Rotate

An extra rotation that can be applied to align your object as you wish, again you can always use a parent object and use your game objects local transforms as well.

Late Update

Check this if you want to do positioning in the Late Update instead of normal Update, you may need this if your lofts are animating for example.

Walk Loft Class

public class MegaWalkLoft : MonoBehaviour
{
    public MegaShapeLoft    surfaceLoft;
    public int              surfaceLayer;
    public float            alpha;
    public float            distance;
    public MegaWalkMode     mode;
    public float            crossalpha;
    public float            delay;
    public float            offset;
    public float            tangent;
    public Vector3          rotate;
    public bool             lateupdate;
}

Example

This simple class will move an object along a Shape Follow using the W and S keys.

using UnityEngine;

// Example script to move an object along a Mega Shape Follow using keys
public class MovePlayer : MonoBehaviour
{
    public float distance = 0.0f;   // Position
    public float speed = 1.0f;      // Movement speed
    public MegaWalkLoft loft;   // walk loft object to control

    void Start()
    {
        if ( !loft )
            loft = (MegaWalkLoft)GetComponent<MegaWalkoft>();

        if ( loft )
            loft.mode = MegaWalkMode.Distance;
    }

    void Update()
    {
        if ( Input.GetKey(KeyCode.W) )
            distance += speed * Time.deltaTime;

        if ( Input.GetKey(KeyCode.S) )
            distance -= speed * Time.deltaTime;

        if ( loft )
            loft.distance = distance;
    }
}

Walk Loft Video

You must be logged in to post a comment.