Hello,
I have a set of enemies currently moving to a set object. This object is on the far left of my game, and another object is at the far left. How could I make the enemies individually move to a random spot between these objects? This is my current code for their movement;
void Update() {
transform.position = Vector3.Lerp(startingPos, endingPos,
Mathf.SmoothStep(0f,1f, Time.time/secondsForOneLength));
}
Also, for some reason while using the above code my collider isn’t applying the AddForce I’ve set to it. If I remove the code for their movement, it’ll work just fine.
Here’s the code for my collider;
void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.tag == "Enemy") {
other.GetComponent<Rigidbody2D>().AddForce(new Vector2(speed, speed));
}
}
Been struggling with this for some hours now. Any help much appreciated!