- Home /
How to get an AI move around in an asteroid field
Hello!
I'm trying to implement a fairly basic AI, just chase and flee. But I also obviously want collisiondetection. For this I am using Spherecasting to see if there is comething in front of my object and this far it works. When I see that there is something in front of my object I want to rotate my AI in relation to the normal to get the least amount of rotation needed to get around.
So I need the Eular Angels of the current transform in relation to the asteroids normal.
Vector3.Angels can't do this as that returns the value in a float. I'm really stuck and I need help, thanks in advance!
EDIT: After a bit of experimenting and a bit more looking around I discovered that Quaternion.LookRotation can achive this. Here's the code I have currently:
Physics.SphereCast(this.transform.position, sizeofcolldetec, Vector3.forward, out Coll, rangeofcolldetec);
if(Coll.collider.CompareTag("Asteroid") && !Coll.collider.CompareTag("Player")){
targetrot = Quaternion.LookRotation(transform.position - Coll.normal * dampening);
}
If there are other ways to do that or if this is an incorrect way of doing it I'd love to know!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
'The type or namespace name could not be found' 1 Answer
First child of a gameobject 3 Answers
Any one knows how this is done? 1 Answer