Question by
supereze8 · Apr 28, 2017 at 04:04 PM ·
c#rotate objectcharacter movement
Strange rotation in my character
Hi everyone! I'm making a game like a Sims. I've programmed a click and move system, and when my character is close to the object I change the position with transform.position = object.transform.position to move my character into the chair position. My problem is that my character start to move strangely when changing position. It may work by changing the character rotation manually. But I am very beginner, and I am not very informed of how to do it. At this moment I am using a cube as a test before entering the mesh of the chair. I'm sure the cube is in Trigger mode, so it does not collide with the character.
MY CODE:
public class Sentarse : MonoBehaviour
{
public GameObject silla;
static Animator anim;
private float Distancia;
void Start ()
{
anim = GetComponent<Animator> ();
}
void Update ()
{
Distancia = Vector3.Distance (silla.transform.position, transform.position);
if(Distancia<1)
{
anim.SetBool ("isSentarse", true);
transform.position = (silla.transform.position);
}
if(Distancia>0.5)
{
anim.SetBool ("isSentarse", false);
}
}
}
Thanks you for your attention!
Comment