Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Avoid incoming objects by aproach side

$
0
0
have this code that detect objects to be close to my GO, but i want it to detect which side of the object is aproaching to add the right side force to it: void Update() { GameObject[] Bullets; Bullets = GameObject.FindGameObjectsWithTag("Bullet"); foreach (GameObject bullet in Bullets) { if(Vector3.Distance(transform.position, bullet.transform.position) < 1.5f) { shouldEvade = true; //print("EVADE!"); } else { shouldEvade = false; } } if(shouldEvade) { rigidbody.AddForce((transform.right * 10) * Time.deltaTime, ForceMode.VelocityChange); } Debug.DrawRay(transform.position, transform.forward, Color.red); }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>