1
\$\begingroup\$

I have a enemy npc that moves left and right in a corridor. It's animated with 2 sprites using Orthello 2D Framework.

If I untick the animation's play on start and looping, the npc moves correctly.
If I turn it on, the npc tries to move but is pulled back to his starting position again and again because of the animation loop.
If I turn looping off during runtime, the npc moves correctly again.

What did I do wrong?


Here's the npc code if needed.

using UnityEngine;
using System.Collections;

public class Enemies : MonoBehaviour 
{
    private Vector2 movement;
    public float moveSpeed = 200;
    public bool started = true;
    public bool blockedRight = false;
    public bool blockedLeft = false;
    public GameObject BorderL;
    public GameObject BorderR;


    void Update () 
    {
        if (gameObject.transform.position.x < BorderL.transform.position.x)
        {   
            started = false;
            blockedRight = false;
            blockedLeft = true;
        }
        if (gameObject.transform.position.x > BorderR.transform.position.x)
        { 
            started = false;
            blockedLeft = false;
            blockedRight = true;
        }


        if(started)
        {
            movement = new Vector2(1, 0f);
            movement *= Time.deltaTime*moveSpeed;
            gameObject.transform.Translate(movement.x,movement.y, 0f);
        }
        if(!blockedRight && !started && blockedLeft)
        {
            movement = new Vector2(1, 0f);
            movement *= Time.deltaTime*moveSpeed;
            gameObject.transform.Translate(movement.x,movement.y, 0f);
        }
        if(!blockedLeft && !started && blockedRight)
        {
            movement = new Vector2(-1, 0f);
            movement *= Time.deltaTime*moveSpeed;
            gameObject.transform.Translate(movement.x,movement.y, 0f);
        } 
    }
}
\$\endgroup\$
3
  • \$\begingroup\$ Related: gamedev.stackexchange.com/questions/7256/… \$\endgroup\$ Nov 5, 2012 at 13:55
  • \$\begingroup\$ I've only just started with animations and my programming knowledge is not that vast either, so I'm failing to see how that is related. From what I understand that person has a sync problem between the moving animation and the actual movement. My problem is I can't move at all. \$\endgroup\$ Nov 5, 2012 at 19:04
  • \$\begingroup\$ Woo, Orthello! I liked it. \$\endgroup\$ Nov 6, 2012 at 1:48

1 Answer 1

1
\$\begingroup\$

Found the problem.
There was a change in orthello's version 2.4c (dirtychecks=false) that made gameObject.transform not work.
sprite.position should be used instead.

LINK

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .