As the NavMesh is not working in Direct mode, I've created some Collision Cubes 2D (from the Scene tab) to draw the limits of the scenary. Besides, for the character I've created a Rigidbody 2D (freezing positions has not effect) and a Circle Collider 2D, and made the Player section to Ignore gravity (or it goes down).
And it works: my character doesn't cross the colliders. The problem is, as I've said, that it's moving all the time as it was walking in the same direction. I'd like to put him in an idle state just after the collision.
Thank you very much if someone can help!
(By the way... I'm a beginner in Unity issues. Sorry )
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I've found a "craft" way to solve part of the problem. When the distance between the position in a Update event and next is lower than some number, the animator component speed is 0. Otherwise, animator component speed is set to a default value. See the code below:
#pragma strict
public var MovementThreshold : float = 1;
public var WalkingSpeed: float = 1;
private var animator: Animator;
private var lastPos: Vector3;
function Start () {
animator = this.gameObject.transform.GetChild(0).GetComponent.<Animator>();
lastPos = new Vector3(0, 0, -10);
}
function Update () {
if (Vector3.Distance(this.transform.position, lastPos) * 1000 < MovementThreshold)
animator.speed = 0;
else if (animator.speed == 0)
animator.speed = WalkingSpeed;
lastPos = this.transform.position;
}
It's perfect with the default values. My problem now is that I'm not able to change the animator to "Idle" (for example, "BrainIdle"), so, the character remains in an unnatural position. I've tried with animator.Play, but it can't get it.
Any help?
Thanks!
Sprites Unity Complex, however, allows you to play your animations using regular Mecanim parameters, e.g. "movement speed", "facing direction" etc. AC will control the parameters and nothing else - therefore, you can insert your own parameters, and control them through script. If you're going down the custom script route, that'd be your best bet.