Tag Info

New answers tagged

0

I will assume you are using a DragListener or something similar to achieve the "panning" effect. This is the method I have that keeps the camera within its bounds: private void keepCameraInBounds () { Camera c = this.getCamera(); Vector3 camPos = c.position; float HW = c.viewportWidth / 2, HH = c.viewportHeight / 2; camPos.x ...


0

for anyone else wondering how to do this. Try this: http://www.david-gouveia.com/portfolio/limiting-2d-camera-movement-with-zoom/


2

user1118321's answer will provide you the correct answer, though it is more general than necessary. Since we're dealing with a right triangle, the easiest solution is to use the definition of the tangent function: tan(α) = A / B Substituting half the height of the screen, the z coordinate of the camera, and half the vertical field of view gets us: ...


2

Check out the Law of Cosines. It allows you to calculate any side or angle in a triangle if you have the opposite 2 angles or sides. Or alternately, use the law of sines (described at the bottom of the above link). In your case, you know that vertical field of view is 45 degrees and that the base side you want is the height of the screen. You can think of ...


0

The World/Model matrix moves objects from object-space to world-space. World coordinates have no software-defined min/max values. The View matrix re-centers the scene on the camera. It is the anti-world-matrix for the entire scene. Since the camera's View-space location is (0,0), objects are either left/right or down/up, corresponding to -/+ coordinate ...


2

Iterating through the faces: faceNormal[i].dot(-worldViewVector) > 0.8 //(should actually be >0.9999) If you do an if/switch to apply a rotation to the cube(or camera): Just update and store a value indicating the front face at the same time. This actually works the same for non-snapping angles such as your scene view. In the orthogonal mode, the ...


1

one solution is to remove the directional light and relay only on other lights; then set ambient light near to dark.


1

Just make the main camera a child of the player object in the hierarchy, then move it to where you want it in the scene view with the translate/rotate tools. Don't make it overly complicated with code. Or apply the same control scripts and colliders to the camera as to the player object.


0

Ok, so I'll tell you what I came up with in my project. attach a script to your Main camera object, declare a player like public GameObject player; initialize it in the Start function (be sure you set your character tag to "Player" in this case) like player = GameObject.FindGameObjectWithTag ("Player"); and then in the Update (assuming your character ...


0

i dont like (Mathf.Abs(target.transform.position.x))-(Mathf.Abs(transform.position.x)) Instead I'd like (Mathf.Abs(target.transform.position.x-transform.position.x)) try it


1

You need to clamp the vertical rotation. I don't know off the top of my head the simplest way to adjust that code, but it'll just involve changing a couple lines around the transform.RotateAround() stuff, to use Mathf.Clamp() for the angle around the x-axis. I think you just need to put in y = Mathf.Clamp(y, -180, 180); right after incrementing y. This way ...


1

The key is to analyze how an actual camera would work. If you're pointing it toward, say, a wall in front of you, then you point it toward the ceiling, and then keep turning it "up" you will find that the ground will actually start to come into view from the top. It seems odd at first - but the actual camera configuration you have is already "correct" IMO. ...


1

Update runs once per frame. Using while in the update script like that, in English reads like this: "Once for this frame, while the mouse button was held down for this frame, move the camera and stuff". The reason why this does not work well is because, the mouse will be in a 'down' state until the next frame, and it wont go onto the next frame until the ...


0

you can disable MouseLook for a small amount of time? using invoke to reactivate after "disableTime" float disableTime = 0.5f;//0.5 second disable void reactivateML() { mouseLook.enabled = true; } ... mouseLook.enabled = false; transform.Rotate (-5, 0, 0); Invoke("reactivateML", disableTime); ...


3

You can use the OnBecameInvisible callback for that. Just implement something like: void OnBecameInvisible(){ // disable or destroy gameobject } The method will get called when the object isn't being rendered by any camera anymore. This also includes cameras from the Unity-Editor. So if you're running your game and have the Game and the Scene view ...


1

Hello I suggest you use Raycasting to test if the camera is directly pointing to the light source. The ray will go from the camera into the front vector direction, Once you get the RaycastHit, you can check the name, the tag or even use Layer Mask to selectively ignore colliders. If you want to apply the effect even when the camera is not pointing directly ...


0

The turn my comment up there to an answer : The "proper" way to use Lerp in your case would be that : Vector3 originalCameraPosition; bool hasBeenSet = false; public void OffsetCamera() { //Call that every Frame if(!hasBeenSet ) originalCameraPosition = cameraPosition; cameraPosition = Mathf.Lerp(originalCameraPosition , originalCameraPosition - ...


0

It seems like what you want is a camera target attached to the character as a child, which your camera will continuously move to look at. When your character ducks, you'll move the target a certain amount relative to the character, instead of the camera itself. Also, rather than lerping I would suggest using SmoothDamp to align the camera a fixed distance ...


4

This is entirely a matter of convention. (Since you didn't mention any particular tools.) But! If you are modeling in the same default orientation as your screen, which you say is right-handed, X-right, Y-up, and therefore Z-towards-you, then it would be natural to model your characters facing you, where forward is Z-positive. Which also implies your ...



Top 50 recent answers are included