- Home /
 
Transform.translate change
Hi guys! I've followed a tutorial that uses transform.translate to make an enemy (using enemy state machine move). However, in the tutorial, it calls to use a character flip bool and I don't want my character to flip in whatever direction it is looking in. How can I use Transform.translate to move the enemy instead? Here is my code: it takes place in the Move function.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Enemy : Character {
 
     private IEnemyState currentState;
 
     public override void Start()
     {
         base.Start();
 
         ChangeState(new IdleState());
     }
 
     void Update()
     {
         currentState.Execute();
     }
 
     public void ChangeState(IEnemyState newState)
     {
         if (currentState != null)
         {
             currentState.Exit();
         }
 
         currentState = newState;
 
         currentState.Enter(this);
     }
 
     public void Move()
     {
         MyAnimator.SetFloat("Speed", 1);
 
         transform.Translate()
     }
 
    
 }
   
 
              
               Comment
              
 
               
              Answer by sirjoan620 · Dec 13, 2017 at 01:42 AM
You're missing something. In 37th line you should get an error.
Check this out: Transform.Translate from Docs
 bool isFlip = true;
 float direction = isFlip ? 1.0F : -1.0F;
 
 transform.Translate(Vector3.forward * direction * Time.deltaTime * Speed);
 
 //Or you can use directly
 
 transform.Translate(Vector3.forward * Time.deltaTime * Speed);
 
              Your answer
 
             Follow this Question
Related Questions
How To Make Enemy Move Around 0 Answers
Friction 0 material not working with Transform.Translate 0 Answers
How to move a prefab to a gameobject position? 1 Answer
Move object forward 1 unit then stop 2 Answers