Here you go, it’s in C#. I tested with a character that has a rigidbody controller and it works well.
using UnityEngine;
using System.Collections;
public class pushBack : MonoBehaviour {
public int pushDir = 10;
public int pushBackSpeed = 1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter (Collision collision) {
if (collision.gameObject.tag == "Wall" ) {
Debug.Log("Collided");
transform.position = transform.position +
transform.forward * -1 * pushBackSpeed;
//gameObject.rigidbody.velocity.y = pushDir;
}
}
}