Forum rules - please read before posting.

CustomControllerLink for 2D character

edited November 2015 in Technical Q&A
Hidy ho,

It's been a while since I've been deep in the weeds of AC, but I have a question related to using it with one of Unity's character controllers.

The tutorial at http://www.adventurecreator.org/tutorials/adding-custom-motion-controller is written using the 3D motion controller, and I tried applying the same code/logic to the Platformer 2D controller I'm using (which comes with Unity 5's standard assets). I got as far as blocking player input during cutscenes, but I can't seem to manually disable player input/movement using the engine > manage systems action, or get the character to obey walkto actions.

Here's what I have:

using UnityEngine;
using System.Collections;
using AC;
using UnityStandardAssets._2D;

public class ACCustomControllerLink : MonoBehaviour
{
private PlatformerCharacter2D controller;
private Platformer2DUserControl control;
private Player player;
private Vector3 targetpos;

// Use this for initialization
void Start () {
controller = GetComponent<PlatformerCharacter2D>();
control = GetComponent<Platformer2DUserControl>();
player = GetComponent<Player>();
}
// Update is called once per frame
void Update () {
control.enabled = player.CanBeDirectControlled();
targetpos = player.GetTargetPosition();

if (player.CanBeDirectControlled () == false) {
controller.transform.position = targetpos;
}
}
}

Comments

  • The input/movement locks are defined in the StateHandler script, but these are read-only because only the StateHandler requires them.

    Instead, you should use the Player: Constrain Action to limit movement.  Locking "Movement" (or "Up movement", depending on your settings) will affect the output of the following bool check:

    KickStarter.playerInput.CanDirectControlPlayer();

    Use that in place of your placer.CanBeDirectControlled() check.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.