Hot answers tagged

3

Assuming that you're making a 3D game, you can use Physics.OverlapSphere to get a an array of Colliders that are within a certain range of the player. To check if the object is "visible" to the player, you could simply call Physics.Raycast in the direction of the object(s) returned by OverlapSphere and check if nothing that isn't the object you're checking ...


3

Instead of foreach, you'll want to use for. for (int i = 0; i < position.Count; i++) { Vector3 posit = position[i]; ... } This way, you'll be able to access the previous position using position[i-1]. Keep in mind, however, that this won't work if i == 0 because you can't go less than zero, so you'll want to add some checks to ensure i > 0 ...


2

Both XNA and Fabian Giesen’s implementation behave correctly. Transforming vector (1, 0, 0) by quaternion (w=0.6532815, x=-0.270598, y=0.270598, z=0.6532815) does resut in (0, 0.7071, -0.7071). It also does in Unreal Engine, in my own quaternion implementation, as well as in Wolfram Alpha. Wolfram Alpha also gives the 3×3 matrix equivalent of the ...


1

I would do the following: have your vector u (ensure it’s normalised) pick an orthogonal vector v using any existing method (ensure it’s normalised) pick a random angle α a good random unit vector is therefore: v·cos(α) + (u × v)·sin(α) If you wish your vector to also have random length, you can then multiply it by a random number, or possibly by the ...


1

You can use the dot product trick to get a list of instances actually visible by the player (thus lying inside the camera frustum), and check for the distance from your camera object to get the closest one. First, you can test a certain number of instances so that their distance is low enough for them to be considered "near" the camera (or the player). ...


1

As mentioned in the comments you probably want a Raycast. An example of how to implement a forward-facing raycast in a Fixed Update cycle is spelled out exactly in the Unity Scripting API Documentation here. This will return true if the raycast strikes a collider in front of whatever object you attach the script to. From the documentation above: using ...


1

So I guess you could save like the last 10 rotations in a List and get the average of them with this function. The function return could be set as your final rotation. This should smoothen your rotation. private Quaternion calcAvg(List<GameObject> rotationlist) { if (rotationlist.Count == 0) throw new ArgumentException(); float x, y, ...


1

For posterity...it ended up being a simple handedness issue, but only around the Y (pitch) axis. I had it stuck in my head that positive pitch increases Z and negative pitch decreases Z, which isn't true in a right-hand system. Lesson learned!



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