Player bounces off of enemy. Help!!
I have a basic 2d topdown sumo game, where the player is against the computer(who moves around), I want the player to bounce of the computer player on collision. I tried to do it myself but I think the player movement script it stopping this from happening. Can someone please help me. Here's my script:
using UnityEngine;
using System.Collections;
public class GotoMouse : MonoBehaviour {
public float speed = 1.5f;
private Vector3 target;
void Start () {
target = transform.position;
}
void Update () {
if (Input.GetMouseButtonDown(0)) {
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
}
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
}
Thank you!!
Answer by Rostam24 · Sep 19, 2015 at 01:25 PM
Either disable that script when the player is being bounced, or use addForce for movement instead.
Easiest way to disable the script: have a bool at the top: isBeingBounced. Then in the update put an if(!isBeingBounced) above the move script. Or use AddForce for movement, so figure out which direction to move towards then use rigidBody.AddForce in that direction.
Thanks for the effort, I tried out what you suggested however it didn't work. Any other solutions?
Your answer
Follow this Question
Related Questions
Bouncy on player not working 0 Answers
UI Scroll View object is not moving 0 Answers
OnCollisonStay2D not working please help! 0 Answers
Rigidbody Bounces Off Box Collider 2 Answers
Bounce a ball with same height but faster movement 0 Answers