I’m trying to make a top down 2d bouncing square. when it hits a wall it should not rotate and should bounce in a v shape. But my code doesn’t do that and I’m not sure how I can do that
using UnityEngine;
public class EnemyXYULaxis : MonoBehaviour
{
public float speed = 2.0f;
public float shmovinUpLeft = 1;
void Update () {
if(shmovinUpLeft == -1){
transform.position += transform.up * -1 *speed * Time.deltaTime;
transform.position += transform.right * speed * Time.deltaTime;
}
if(shmovinUpLeft == 1){
transform.position += transform.up * speed * Time.deltaTime;
transform.position += transform.right * -1 * speed * Time.deltaTime;
}
}
//hitting wall
private void OnCollisionEnter2D(Collision2D collision){
if(collision.gameObject.CompareTag("Wall")){
//bouncing
shmovinUpLeft = -1 * shmovinUpLeft;
}
}
}
I’ve look for other guides but couldn’t find one for squares and they had gravity