[./Runtime/Camera/Camera.cpp line 3415]
(Filename: ./Runtime/Camera/Camera.cpp Line: 3415)
Screen position out of view frustum (screen pos 850.000000, 362.000000) (Camera rect 0 0 1334 750)
UnityEngine.Camera:ScreenPointToRay(Vector2, MonoOrStereoscopicEye)
UnityEngine.Camera:ScreenPointToRay(Vector3, MonoOrStereoscopicEye)
UnityEngine.Camera:ScreenPointToRay(Vector3)
UnityEngine.EventSystems.PhysicsRaycaster:ComputeRayAndDistance(PointerEventData, Ray&, Single&)
UnityEngine.EventSystems.PhysicsRaycaster:Raycast(PointerEventData, List`1)
UnityEngine.EventSystems.EventSystem:RaycastAll(PointerEventData, List`1)
UnityEngine.EventSystems.PointerInputModule:GetTouchPointerEventData(Touch, Boolean&, Boolean&)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.StandaloneInputModule:Process()
Error in iphone, but pc and android is no problem! How to Solve It?
↧
Screen position out of view frustum
↧
How to send Cinemachine Virtual Camera Output to OBS
Hi, I was wondering if it'll be possible to send an output from a cinemachine virtual camera to external software like OBS to record from inside of Unity when the play button is pressed or if activated via UI.
The idea that I have in mind is to stream my dev process but be able to switch between different virtual cameras that are place in the scene and have that output be directly connected with a software like OBS to be recorded.
If anyone has any ideas please lmk
Thanks you in advance!
↧
↧
Trying to clamp camera position causes it to get stuck for a few seconds.
yaw += camSpeed * Input.GetAxis("Mouse X");
pitch -= camSpeed * Input.GetAxis("Mouse Y");
Vector3 direction = new Vector3(Mathf.Clamp(pitch, -90, 90), yaw, 0.0f);
Camera.main.transform.rotation = Quaternion.Euler(direction);
My code for rotating the camera is the above. However, when I try using this code, it works... mostly. When I go to one of the limits for long enough, it gets stuck there unless I apply a lot of force moving it back. How would I fix this?
↧
How to set movement limit to Camera in a top-down 3D game
I have a top-down 3D game where I move an object and the camera follows it. The movement of the player is limited by walls (vertical and horizontal if seen from above) that are on the border of the map. When the player is close to a wall I would want the camera to stop following so it doesn't show the parts that are outisde the walls. If the player is close to a vertical wall (seen from above) the x axis of the camera should be frezzed, if the player is close to a horizontal wall, the z axis of the camera should be frozen and if the player is closed to both horizontal and vertical walls the same but with both axis at the same time. Once the player is far enough from the walls the camera should start moving fluently on the axis that has been frozen. This is a mechanic that all top-down 2D games have.
If the map was a square this would be pretty easy. The problem is that I have a lot of maps with different shapes. For one map, for example, at z=5, the x limit is -10, 10 but at z=50 the x limit is -50,50 and at z=60 the x limit is -30,30 (when I say that at z=5 limits are -10, 10 I mean that at (-10, y,5) and at (10,y,5) there are vertical walls).
I have had some ideas. For example, having a box collider on the camera that only collides with walls (this didn't work at all) or use the code below to detect what GameObjects are around the player at a certain range and if it detects a wall, it freezes the corresponding axis, but this is too computationally expensive and it doesn't work well.
Collider[] colliders = Physics.OverlapSphere(transform.position, playerRadius); foreach (Collider collider in colliders) { if (collider.CompareTag("Wall")) { //freeze corresponding axis } }
If you have other alternatives I would love to know them. Thanks.
If the map was a square this would be pretty easy. The problem is that I have a lot of maps with different shapes. For one map, for example, at z=5, the x limit is -10, 10 but at z=50 the x limit is -50,50 and at z=60 the x limit is -30,30 (when I say that at z=5 limits are -10, 10 I mean that at (-10, y,5) and at (10,y,5) there are vertical walls).
I have had some ideas. For example, having a box collider on the camera that only collides with walls (this didn't work at all) or use the code below to detect what GameObjects are around the player at a certain range and if it detects a wall, it freezes the corresponding axis, but this is too computationally expensive and it doesn't work well.
Collider[] colliders = Physics.OverlapSphere(transform.position, playerRadius); foreach (Collider collider in colliders) { if (collider.CompareTag("Wall")) { //freeze corresponding axis } }
If you have other alternatives I would love to know them. Thanks.
↧
Making main camera focus on trigger
Hello, I have a main camera that follows my player all the time, what I want to do is when the player gets to a specific position it triggers the camera to focus on a different area and then smoothly go back to the player (ex.: after 3sec). I tried to do the "Cinemachine 2D tips and tricks" "Group Camera" option but unfortunately i did not managed to do it by myself. The way I kind want it to look like is like this:
https://blogs.unity3d.com/wp-content/uploads/2018/07/cinemachine2d8.gif
Hope I explained well with my English :D
↧
↧
Using VideoPlayer with a Camera as the target ignore other camera's depth.
I am playing a video using the Video Player. When selecting the Camera Near Plane as the render mode. It will always render on top of anything, ignoring the selected camera's depth. This mean that even if another camera is supposed to be rendering on top of the selected camera, it will not.
Besides using render textures, is there a way to play a video on camera, and having the render of another camera on top ?
↧
[Solved] Raycast2D and Main Camera
Hello everybody!
I got a problem with Raycast2D and Camera.
Somehow, my logic works without enter on Maximize on Play, but when i do, everything stops to working.
This is my code
void Update()
{
if (Input.GetMouseButton(0))
{
Vector2 rayOrigin = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hitinfo = Physics2D.Raycast(rayOrigin, Vector2.zero);
if (hitinfo.collider != null)
{
Debug.Log(hitinfo.collider.name);
}
}
}
This is my camera in Full Screen Mode
![alt text][1]
And this is my camera on normal mode
![alt text][2]
[1]: /storage/temp/161009-cameramaximized.png
[2]: /storage/temp/161010-normalcamera.png
Thanks!
[Edit] I tested with my cellphone (via Unity Remote5) and works. Only my maximized is not working.
[Edit2] Guys! I figured out! I forgot to set my canvas UI Scale Mode to Scale with Screen Size and my render mode to Screen Space - Camera
↧
How do I change the camera's viewport rect y pos (or x pos) without changing it's size?
Hey guys, I have a very basic scene with a cube in the middle (image below #1).
Whenever I change the y pos (or x pos) of the camera's viewport rect, it changes the viewport rect size (and therefore displays the cube smaller) instead of moving it out of the game view (image below #2).
I'm trying to get it to look like in #3. I don't worry about moving it, it's simply the resizing that is killing me.. Do you have any suggestions?
(so far I've tried *rect.yMax*, *rect.position*, and *rect.size* without any luck)
![the camera issue][1]
[1]: /storage/temp/161172-the-camera-issue.png
↧
How can I prevent my UI sprite from shaking when the camera shakes as well?
I have a coin in my UI that I didn't wanted to shake when the camera shakes. I am using the asset EZ Camera Shaker to shake the camera. Any tips? I've already tried to change the Z of the sprite, order in layer and a couple more things but nothing seems to work
↧
↧
Camera gets flung off of the map when the player collides with certain objects.
When the player collides with a collider and I move forward a lot, the camera gets flung far from the map and orbits it when I look around. How do I fix this?
[Here is a video showing the issue][1]
[1]: https://drive.google.com/file/d/1WNxfDaLt3XLzKre8tOhAyqrZhnpvKCHV/view?usp=sharing
↧
Cinemachine camera shake on button press
Hello! I was using a camera script on the main camera that made the camera shake whenever I pressed x (This makes my character dash). I switched to Cinemachine in order to move the camera around to certain areas. Now I am not sure on how to implement the camera shake when X is pressed while using Cinemachine. Here is what the script on my camera looked like:
void Start()
{
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
}
// Update is called once per frame
void Update()
{
hasDashed = character.hasDashed;
Vector3 temp = transform.position;
temp.x = playerTransform.position.x+xPos;
temp.y = playerTransform.position.y+yPos;
transform.position = temp;
transform.position = new Vector3(Mathf.Clamp(transform.position.x, leftLim, rightLim), Mathf.Clamp(transform.position.y, botLim, topLim), transform.position.z);
if (Input.GetKeyDown(KeyCode.X) && hasDashed)
{
Debug.Log(hasDashed);
StartShake(shakeTime, shakeIntensity);
}
Debug.Log(hasDashed);
}
private void LateUpdate()
{
if(shakeTimeRem > 0)
{
shakeTimeRem -= Time.deltaTime;
float x = Random.Range(-1f, 1f) * shakeIntensity;
float y = Random.Range(-1f, 1f) * shakeIntensity;
transform.position += new Vector3(x, y, 0f);
}
}
void StartShake(float length, float power)
{
shakeTimeRem = length;
}
Any suggestions? Thanks :D
↧
Disable Camera Movement,Stop camera movement
Hi!
I'm new to all of this and I'm coming across the first problem.
I got a simple code to move my object, but while in play my topdown camera also moves while holding down the keys. I didn't find an option to disable this, so what do I need to do to just move my object, not the view?
Here an example code I'm using:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
transform.position = new Vector3(0, 10, 0);
}
// Update is called once per frame
void Update()
{
Vector3 input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
print(input);
}
}
↧
Object in Camera Frustum in Scene View, but not visible in Game View?
![alt text][1]
[1]: /storage/temp/161194-unity-problem.png
So, in this project, the floor is dotted with triangles that each move to a different random location within the FOV every 0.25 seconds, while there is a circle that also spawns randomly within the FOV, except it stays there for 10 seconds. The goal is to move and land as close as possible to the circle.
The circle spawns correctly within the camera frustum, as shown, but why can't I see it in game view? I have the aspect ratio set to 16:9 and the vertical FOV is 68.
↧
↧
CineMachine Camera Movement is inverse
So I just watched Brackeys 3d player movement, and I noticed that my camera was sort of inverse, If I move my cursor left and press 'W' it goes to the right, and vice versa![alt text][1]
[1]: /storage/temp/161247-screenshot-62.png
If anyone can help, or needs more information how to solve, thanks
↧
Cinemachine Freelook Camera Movement with Joystick
I'm trying to make a third person RPG that's controlled with a gamepad. I am using the Cinemachine Freelook camera and Unity's Input System. So far the gamepad works just fine in making my player character move and perform actions; however, I want to control the camera's rotation with the right joystick. Only the mouse can control it's movement right now, and I don't want the mouse to control it at all. If anyone knows a script or a setting change that will get me these results, please let me know.
↧
How do you use a camera strictly for a render texture?
The camera that I have created for my render texture is also displaying things in game when it is lined up with the main camera. This results in the elements in the UI layer showing up in the main camera. How do you prevent the two camera views from overlapping?
↧
Player jitters when moving.
Help!! So I have been suffering with this for the past few days. I'm not sure if I should redo the code or what, but I have made so much progress so far so I'm uncertain about doing that. I don't want to wait to long to fix this either
The goal is to have a player shoot while facing the direction of a crosshair. The player itself is shooting though, not a pistol coming from a player. The problem is, the player shakes when it moves, even though it's able to shoot perfectly. I believe the problem is that the player rotates in one script file while the player moves in the other. Let me show you:
**Connected to the camera object:**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PointAndShoot : MonoBehaviour
{
bool allowfire = true;
public GameObject crosshairs, player, bulletPrefab, b;
public float fireRate, bulletSpeed, currentAmmo, maxAmmo, AmountOnScreen, rotationZ;
private Vector3 target;
Vector3 difference;
// Use this for initialization
void Start()
{
currentAmmo = maxAmmo;
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
if (player != null)
{
if (Cursor.visible == false)
{
target = transform.GetComponent().ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z));
crosshairs.transform.position = new Vector2(target.x, target.y);
difference = target - player.transform.position;
rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
player.transform.rotation = Quaternion.Euler(0.0f, 0.0f, rotationZ);
}
if (Cursor.visible == true)
{
target = new Vector3(0, 0, 0);
player.transform.rotation = Quaternion.identity;
}
if (Input.GetMouseButtonDown(0) && allowfire)
{
float distance = difference.magnitude;
Vector2 direction = difference / distance;
direction.Normalize();
StartCoroutine(fireBullet(direction, rotationZ));
Debug.Log("Ammo: " + currentAmmo);
}
}
IEnumerator fireBullet(Vector2 direction, float rotationZ)
{
if (currentAmmo > 0)
{
allowfire = false;
b = Instantiate(bulletPrefab, player.transform.position, Quaternion.identity) as GameObject;
//b.transform.position = player.transform.position;
//b.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
b.GetComponent().velocity = direction * bulletSpeed;
yield return new WaitForSeconds(fireRate);
currentAmmo--;
allowfire = true;
}
}
}
public float AmmoToGive(float ammoGiven)
{
if(currentAmmo < maxAmmo)
{
if(ammoGiven <= 0)
{
return ammoGiven;
}
if(currentAmmo + ammoGiven <= maxAmmo)
{
currentAmmo += ammoGiven;
return 0;
}
//get the difference between maxAmmo and currentAmmo
float diff = maxAmmo - currentAmmo;
//difference added to current ammo
currentAmmo += diff;
Debug.Log("Received " + diff + " bullets.");
//return the ammo that wasn't used
return (ammoGiven - diff);
}
return ammoGiven;
}
}
**Connected to the Player:**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerMovement : MonoBehaviour
{
//public Image healthBar;
public int playerMaxHealth = 100;
public int playerCurrentHealth;
public int dmg;
public float mSpeed;
Rigidbody2D rbody;
public Slider healthbar;
public bool alive;
// Start is called before the first frame update
void Start()
{
playerCurrentHealth = playerMaxHealth;
rbody = GetComponent();
alive = true;
}
// Update is called once per frame
void Update()
{
//movement
float moveX = Input.GetAxis("Horizontal");
float moveY = Input.GetAxis("Vertical");
Vector2 move = new Vector2(moveX,moveY);
rbody.velocity = move * mSpeed;
healthbar.value = playerCurrentHealth;
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.CompareTag("Enemy"))
{
int health = GetDamaged(dmg);
Debug.Log("Health is now:" + health);
if (health <= 40 && health != 0) {
Debug.Log("Warning, critical damage!");
}
if (health <= 0) {
healthbar.value = 0;
Destroy(gameObject);
alive = false;
Time.timeScale = 0;
Debug.Log("Game over.");
}
}
}
public int GetDamaged(int attackdmg)
{
playerCurrentHealth -= attackdmg;
return playerCurrentHealth;
}
}
↧
↧
Render Gameobjects in one specific Layer as transparent,
Hi. I have a 2D scene with a second Camera that I have configured to only render the Gameobjects in two specific Culling Layers. This Camera renders to a RenderTexture, that I later use to apply a fake lighting effect to the scene.
All of these Gameobjects are ordered in the same Sorting Layer, but I would like the Gameobjects in one Culling layer to render as transparent, **on top** of any Gameobjects they ocude in the other Culling Layer.
For example, if the Circles are in Culling Layer A and the Square is in Culling Layer B, I would like the square to render as transparent obscuring part of the blue circle
I think that I could do this using a complicated arrangement of **Camera.RenderWithShader** and shaders with **RenderType** tags, but I was wondering if there is a simpler or more elegant way to achieve this.
**Objects in Sorting Layer:**
![alt text][1]
**Desired Output Texture:**
![alt text][2]
[1]: /storage/temp/161360-untitled.png
[2]: /storage/temp/161362-untitled2.png
↧
Reposition Camera Behind Player with Button Press
I have a 3D character that moves in all directions and a camera that rotates around them in all direction. My camera rotates around using Cinemachine's Freelook camera (this might not be relevant). I just want the camera to reposition behind my character whenever I press a certain button. I'm not used to programming camera behavior so this is pretty new to me. If anyone knows what can help me, please let me know.
↧
Is it possible to zoom in or out with the pixel perfect camera?
I recently applied the pixel perfect component to my camera and have since then disabled it because I can't zoom with it. I understand orthographic size can't be changed but is there another way to do this?
↧