- Home /
This question was
closed Oct 20, 2015 at 11:00 AM by
devereux for the following reason:
I have solved the problem
Question by
devereux · Oct 20, 2015 at 12:02 PM ·
scriptingbasicsanimator controllerscriptingproblem
Animator Controller
Alright, So I have a NPC from the Morph3d Male character pack.
In the Object I have a Transform, Animator, Rigid Body, Capsule Collider, M3d Character Manager(Script), and my own script.
I am still trying to just figure unity out, but I have set the Animator controller, to "ThirdPersonAnimatorController".
I made a script, which to my understanding should allow me to move that character towards my character. It however just makes the character rotate spherically in the air.
Can someone help put me on the right track? Here is my script.
using UnityEngine;
using System.Collections;
public class WalkToPlayer : MonoBehaviour {
private Animator controller;
public Transform playerTransform;
public bool isWalking = false;
public float dampening = 2;
public int minDistance;
public void start()
{
controller = GetComponent<Animator>();
}
private void update()
{
float distance = Vector3.Distance(playerTransform.position, transform.position);
if (distance > minDistance && !isWalking)
{
isWalking = true;
setWalking(0.5f);
}
if (isWalking)
{
if (distance < minDistance)
{
isWalking = false;
setWalking(0.0f);
}
}
// Handles rotation
Quaternion t = Quaternion.LookRotation(playerTransform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, t, Time.deltaTime * dampening);
}
public void setCrouching(bool b)
{
controller.SetBool("Crouching", b);
}
public void setWalking(float f)
{
controller.SetFloat("Forward", f);
}
public void setTurn(float f)
{
controller.SetFloat("Turn", f);
}
public void setJump(float f)
{
controller.SetFloat("Jump", f);
}
public void setJumpLeg(float f)
{
controller.SetFloat("JumpLeg", f);
}
}
Comment