Tag Info

New answers tagged

0

Based on the comments above, the followed object "Current" is only moving in FixedUpdate. By default, FixedUpdate runs 50 times per second. In-between FixedUpdates, Unity renders as many frames as it can, each time calling Update, LateUpdate, etc. Because the rendered framerate is usually not a perfect multiple of the FixedUpdate rate, this can cause a ...


0

Try this: using UnityEngine; using System.Collections; public class RotateTheCamera : MonoBehaviour { private float targetAngle = 0; private float currentAngle = 0; void Update () { float mouseXChange = Input.GetAxis("Mouse X"); targetAngle += mouseXChange * 10; if (targetAngle < currentAngle) { ...


0

From what you have posted I have a few pointers: There are some Follow scripts you can try to tinker with in the standard assets: **Standard Assets\Utility** and **Standard Assets\2D** You shouldn't have Find functions inside Update() loops as it might slow down your game. Here is how your code can include that: (not the solution just an improvement) ...


1

You can use Vector3.Lerp(transform.position, WAYPOINT POS, Time.deltaTime) for smooth movement from one point to another.


0

The only possibility based on your snippet would be all the collection iterations it has to do each line to find stuff. If you have a lot of objects to hunt through, maybe that could influence performance to cause the stutter although I doubt it. Have you profiled the code to see if it's a garbage collection issue somewhere other than this snippet? Are you ...


1

Many 2D games are actually 3D with most objects fixed in certain planes (Unity 2D for example). If this were the case, you could quite literally just move the camera backwards as a quick fix. However, you mentioned processing! Processing utilizes affine transformations, and has a built in transformation stack. It's hard for me to remember exactly what the ...


1

I'm assuming you are using two different cameras (as you probably should). If so, then the script below should work for what you want. Attach this script to the player (or any gameobject that is always active in your scene). Then be sure to assign the cameras to the script from the inspector. When you are switching cameras, particularly from the other cam ...


1

Looks to me like you should set the yaw and pitch to the current rotation's yaw and pitch whenever you enter the freemode. Should be something simple like if( enterFreemode ) { pitch = transform.eulerAngles.x; yaw = transform.eulerAngles.y; } That should ensure that whenever you enter the free camera, you have the same rotation as the original ...


0

You can multiply vector3 by using vector3.cross(vector a, vector b); And here, its not multiplying to vector3. Its multiplying to just z axis. Transform.forward is z axis.


2

Something like this: transform.position = player.transform.position - player.transform.forward * distance; transform.LookAt(player.transform); where float distance is the distance of camera form player Consider also the solution 2 : Make camera child of player and in your player die script , you can "deatach" camera from player object transform.parent ...


0

The problem is that you are updating the existing rotation instead of tracking it yourself and replacing it each update. When you update the rotation it combines your new rotation with the old one which leads to unexpected behaviour. The solution is to to keep track of your accumulated rotation and reset the rotation entirely each update with your new ...


0

Your orthographic camera size depends on the pixels per unit of your sprites. Orthographic camera size is equal to 1/2 of the vertical units (meters if you use built in physics) you will see on the screen. Say size 6 means that your screen height will be 12 units. The formula is: screen resolution / 2*orthographic size = pixels per unit on sprites


0

What if you make the camera child of an empty gameobject. Then with one script you manage the empty gameobject rotation relative to UP vector.(MouseX) With another script atached to the camera gameobject you manage rotation relative to Right vector (MouseY)


0

Set your Pixel per Unit to 1 and try witch this: scale = Screen.height / nativeRes.y; pixelsToUnit *= scale; cam.orthographicSize = (Screen.height / 2.0f) / pixelsToUnit; Where nativeRes is your default resolution. Attach it to MainCamera and now your orto size should fit automatically.


2

As mentioned above, you can start and stop a SpriteBatch in the same draw-method, also for transparency you need to enable BLEND. Here's what I did with one of my UIs. batchstuff... spriteBatch.end(); Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); ...


1

I've managed to get it working by fiddling around and it would seem that this works as I wanted. `shape.setColor (Color.WHITE); shape.rect ((Constants.RENDER_WIDTH - 500) + (camera.position.x - (camera.viewportWidth * camera.zoom) / 2) / 30, (camera.position.y - (camera.viewportHeight * camera.zoom) / 2) / 30, (Constants.RENDER_WIDTH * camera.zoom) / ...


0

Well if you are incorporating zoom with your camera you have to multiple the rectangle by that. It also depends from where the camera actually zooms, I believe this is the center of the camera but it might be bottom left too. Something like this should leave you with the correct rectangle size. shape.rect ((Constants.RENDER_WIDTH - 500) + ...


0

The dimensions of the Stage (and the parent Group containing the Display Objects) is equal to the absolute value of the combined dimensions and positions of every Display Object in the Group, on the Stage, and in the World. Example: if you have a World that is 100 (width) x 100 (height) but bounded to -50, -50, 50, 50 such that 0,0 is in the center of the ...


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 ...


2

1)Create a plane that usually contain a point and a normal that represents the floor. 2)Reflect your camera position and rotation from this plane. 3)Create a view matrix from these point and rotation. 4)Render scene from this matrix into a texture. 5)Transmiss those texture and matrix into a shader. 6)Project texture onto a surface of floor using ...


0

Check whether it's possible to draw your objects or not when they are out of screen. if(yourSprite.x>screenWidth || yourSprite.x+yourSprite.width<0 || yourSprite.y>screeenHeight || yourSprite.y+yourSprite.Height<0){ //Don't draw } else{ //Draw your sprite } And easily can find whether your sprite is behind of another object or not ...


1

As someone who has implemented an entire Math library including Quaternions let me say that just following a tutorial will not get you anywhere with this. To iron out bugs like this you really need to understand how Quaternions work, what they are and how to use them. It's probably some of the most complicated math in Game development and I don't recommend ...



Top 50 recent answers are included