Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

AI Aircraft/Spacecraft yaw and pitch help

$
0
0
I'm guessing this question has been asked to death, but I'm more looking for how to implement this into my AI code, since right now all they do it just rotate on the y axis and just spin around the enemy in a RotateAround type effect, which doesn't look very exciting. I can easily make aircraft/spacecraft turn on yaw and pitch very easily using the input function and I understand how it works since you use transform.Rotate, but how do I get an AI to do it? I've tried manipulating the LookAt function and turning off the y axis and doing this as well for transform.Rotate but this just gave some very jerky effects and didn't bank the spacecraft at all to turn it. I've thought of using relativetorque but I'd rather someone clarify how to go about it, either with pseudoscript or a snippet of code that I could work with, or even just a general explanation. If this is sounding confusing, then think of it in old Elite style controls, left/right to bank left and right and up/down to pitch up and down, to turn you would bank a bit, then climb or dive, that is the effect i'm looking for. But i'm a little stumped as to how to get the AI to do it, I'll provide a snippet of code that can be used since it is repeated in my code for other behaviours, also it's using a rigidbody system, so it is already moving forward in the fixedupdate() function using AddForce function Patrol () { CanSelectNewWaypoint = false; //var RandomWaypoint : int = Random.Range(0, PatrolRoute.Length); if (Vector3.Distance(PatrolRoute[WaypointNumber].position, transform.position) < 50) { WaypointNumber++; if (WaypointNumber >= PatrolRoute.Length) { WaypointNumber = 0; } } WaypointTarget = PatrolRoute[WaypointNumber].transform; var Rotation = transform.rotation; var Position = WaypointTarget.position - transform.position; transform.LookAt(WaypointTarget.position); transform.rotation = Quaternion.Slerp(Rotation, transform.rotation, 2.0* Time.deltaTime); //transform.Rotate (-Angle * 0.1, 0, -Angle * 0.1); //yield WaitForSeconds (TimeUntilNewWaypoint); CanSelectNewWaypoint = true; }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



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