Tag Info

Hot answers tagged

3

Calculate the dot product to determine how close two vectors are. The dot product is 1 when they are exactly the same, -1 when they are exactly opposite, 0 when they are perpendicular, and decimal values when partway. So take the current direction, the target direction, then Vector3.Dot() and check if greater than .9 (or whatever threshold you decide looks ...


3

If you would follow the second strategy, changes made to the Vector that got passed as parameter "v" will also be made to "vector2", since they are the same object. You should have a look at this question: http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value In Java every object is an reference, so you need to copy, for ...


2

Solution for 2D vectors: Vector2 AB = B - A; // Vector from A to B Vector2 A0 = r * AB.normalized; // Vector from A to 0° Vector2 A90 = new Vector2(A0.y, -A0.x); // Vector from A to 90° Vector2 P = A + Sin(alpha) * A90 + Cos(alpha) * A0; // Coordinate of arbitrary point on a circle For arbitrary 3D vectors A and B in 3D space you need coordinates of ...


2

jhocking's answer about dot product is the right answer to the question, but if you are rotating your object over time to face the right direction, inside that function you must be calculating how much you have left to rotate so that you know what direction to rotate and so that you don't rotate too far and overshoot. That means that inside that function, ...


2

First, it won't solve your problem, but there are a few general problems with your code. The conditions for your if branch will always be true if transform.localEulerAngles.x >= 0 and <= 360. The > 270 part is redundant since if x is less than 270, it is still possible to be >= 0. If x is 0 and lookAxisX is > 0, then adding -lookAxisX will make x < ...


1

You can always try to use the clamp method: Ref: http://docs.unity3d.com/ScriptReference/Mathf.Clamp.html Example transform.localEulerAngles = new Vector3(Mathf.Clamp(transform.localEulerAngles.x, 0f, 90f), 0, 0); **This is just a push in the right direction (above is untested)


1

Since you are working in 3d world space, why not use the BoundingFrustum class? BoundingFrustum cameraBounds = new BoundingFrustum(view * projection); if(cameraBounds.contains(location)) { // it is in view } else { // not in view } edit. I assumed you are using XNA. If not, you can still reflect the XNA code to see how to make a Bounding frustum ...



Only top voted, non community-wiki answers of a minimum length are eligible