Help please with Script

Why enemy falling? And why not working Flip(0 method?

Enemy have 2 Colliders(one trigger, one not)

EnemyBehaviorScript : MonoBehaviour {
private Animator animator;
public int cMaxDistance = 10;
private bool isDead;
public bool isFacingRight=true;
public float speed;
public Transform explosionSpawn;
public GameObject explosion;
public Transform player;
public bool gotcha;

void Start(){

Flip ();

GameObject playerDistance = GameObject.FindWithTag (“Player”);
if (playerDistance != null) {
player = playerDistance.GetComponent ();
}

animator = GetComponent();
isDead = false;
}

private void FixedUpdate(){
animator.SetBool (“isDead”, isDead);
if(!isDead)
rigidbody2D.velocity = new Vector2 (speed, rigidbody2D.velocity.y);
if(speed > 0 && !isFacingRight)//&&!isDead)
//отражаем персонажа вправо
Flip();
//обратная ситуация. отражаем персонажа влево
else if (speed < 0 && isFacingRight)//&&!isDead)
Flip();
}
void Update()
{
PlayerSearch ();
if (isDead) {
if (!(GameObject.Find(“headExplosion(Clone)”)))
Instantiate (explosion, explosionSpawn.position, explosionSpawn.rotation);
}
}

void OnTriggerEnter2D(Collider2D col){

if (col.gameObject.tag == “WeaponTree”) {
isDead = true;

Destroy (gameObject,1.0f);
}
if (col.gameObject.tag == “triggerChangeDirection”) {

speed = - speed;
}
}

private void Flip()
{

//меняем направление движения персонажа
isFacingRight = !isFacingRight;
//получаем размеры персонажа
Vector3 theScale = transform.localScale;
//зеркально отражаем персонажа по оси Х
theScale.x *= -1;
//задаем новый размер персонажа, равный старому, но зеркально отраженный
transform.localScale = theScale;
}
void PlayerSearch(){

float dist = (player.position - transform.position).sqrMagnitude;
gotcha = dist <= cMaxDistance * cMaxDistance; //квадрат расстояния сравниваем с квадратом заданного предела!
if(gotcha)
Debug.Log(“FUCK YOU!”);
}
}

Hello,you schould write this: speed-=speed,that is what y can see…hope y help you

Firstly, can I ask that when posting code, please use the code formatting option in the toolbar when entering post, it just makes it soo much easier to read code :slight_smile:

anyhoo, just to get a feel, I take it this moves an ememy, then when colliding it changes direction? is this movement automatic left and right based on direction facing, ie, based on your value of speed?
would it be easier to alter the speed value in the Flip Function?

doing this would be the equivalent of saying
speed = speed - speed, in other words 0, or a negative number.
the OP i think was right in negating the speed value, or just multiply it by -1 same as the Flip function does for the localX scale. just thinking out loud

not sure about the falling, is this along a flat horizontal surface?

the Flip() function, just to get the ball rolling
im guessing that this is a 2D game, so for the Flip Function, use a Vector2 for theScale

    void Flip()
    {
        isFacingRight = !isFacingRight;
    
        Vector2 theScale = transform.localScale;
        theScale.x *= -1;
        transform.localScale = theScale;
    }

What y wrote,hmmm,shame on me