Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
        } 
    }
}
share|improve this question
    
    
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. –  Nelson Gregório Nov 5 '12 at 19:04
    
Woo, Orthello! I liked it. –  Raven Dreamer Nov 6 '12 at 1:48
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.