- Home /
Need help getting "Directions"...
Hi all,
I seem lost and need help finding my "direction"(excuse the pun...).
So I have a Asset in 3D space (a plane) and it point towards the mouse. Very easy we have all seen the code for this (shown below) many times floating around a number of forums.
I want to have the plane roll as it turns, and I have tried so many different ways to get the angle that the plane is facing (i.e. the Y Rotation's direction). Sorry if this sounds like a nooby question... but I have tried all sorts of transform, trigonometrics, vector equations etc... without success...
The angle of yawn is not critical... I am going for a "toon" apperance, but the idea is that the plane's ange (Y-axis) is generated from 3D space so that it works with any control input from any platform.
I guess the next step will be to determine which direction (+/-) we are talking about and actually rolling the plane. I am sure I can sort this out. But any whizzes out there, if its simple for you, please feel free to save me some time in the future... unfortunately I cannot buy you guys a drink on the internet (but its the thought that counts... I guess)
Best,
T
Here is the all too familiar code for pointing at mouse direction:
var speed = 4.0;
var angle:float=0;
var targetRotation;
var plane:Transform;
var test:float=50;
var spot:Transform;
function Update () {
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
spot.transform.position.z = targetPoint.z;
spot.transform.position.x = targetPoint.x;
Quaternion.Angle (Quaternion.LookRotation(targetPoint.position - transform.position),transform.rotation);
targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.deltaTime);
}
}
Your answer
Follow this Question
Related Questions
Get gameobject limits 1 Answer
Spherical legs rolling where that enemy go and not looking 1 Answer
Tranposing two 3D coordinates onto a 2D plane? 1 Answer
Plane geometry 0 Answers