Hello.
Currently, we're using Command Buffers to manually draw our custom data into the render textures at some certain points in the pipeline. We also have some plane meshes that are rendered by shader with those textures as input. It works almost good, at least in Game View.
However, the Scene View looks completely broken with these meshes in it as their appearance changes each time the Editor's Camera moves and/or rotates and it prevents our artists from doing their job.
![alt text][1]
[Video of such behavior][2].
So the question is: Can we also tell the Editor's Camera to use Command Buffers? Or is there some workaround to avoid such behavior?
P.S. [There is also our topic on support forum about this problem][3] (zero answers).
[1]: /storage/temp/161435-image.jpg
[2]: https://drive.google.com/file/d/1JqOAc974IfQTWEpf4PRRYHoiM4yvsfgN/view?usp=sharing
[3]: https://forum.unity.com/threads/command-buffers-for-the-sceneview-camera.710552/
↧
Command Buffers for the SceneView Camera
↧
How to check if an object is partially outside of the camera view?
I have a scene that loads an asset from the web and you have a camera that orbits this object allowing you to zoom in, out, rotate..etc something like a 3D model viewer. I want the camera position to adjust depending on the object's size so that when the object is loaded not a single part of it is outside the camera view.
I have tried with raycasting and world to viewport point but none of these approaches work as I want. How can I make sure that the camera's position is far enough so that I can see the complete object?
↧
↧
How to clear AR camera's last frame
I have an app where I turn on and off the AR Camera when an event happens, and every time I turn the camera on, the last rendered frame when the camera turned off appears for a split second. I can't, for the life of me, figure out how to avoid this.
I tried having two cameras, one just a background camera that renders black, I tried changing the clearFlags of the AR Camera and render a single frame, I tried a few other things and cannot get the last frame NOT appear when the camera is turned on.
This happens regardless of what Android device I test on.
When I say "turn off" I simply disable the game object the camera is attached to.
↧
Camera layering with post processing?
I've got two cameras, one for the weapon and one for the environment. I've layered the weapon camera above the environment one so it can't clip through geometry. For some reason though, post processing doubles with this setup instead of working the same. Anyone done this before and got any way of fixing this?
↧
How to add avoid the script to overwrite camera collision?
Hi there!
I'm making a kind of a customizer app with one object in the middle so the user can use a camera to zoom on it, rotate, and move around. To create this camera I used the code from this question: https://answers.unity.com/questions/1443572/camera-controls-like-sketchfab-or-similar.html and it works exactly how I want to [it's pasted below].
The problem is that this code disable the collider function. I don't want the user to fly "into" the object, so I need to create a collider for the camera and the object. But the mentioned code does not allow to use standard collider and rigidbody components. How can I use the function OnCollisionEnter (or any other) in this code to prevent the camera from flying into the object?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("Camera-Control/3dsMax Camera Style")]
public class maxCamera : MonoBehaviour
{
public Transform target;
public Vector3 targetOffset;
public float distance = 5.0f;
public float maxDistance = 20;
public float minDistance = .6f;
public float xSpeed = 200.0f;
public float ySpeed = 200.0f;
public int yMinLimit = -80;
public int yMaxLimit = 80;
public int zoomRate = 40;
public float panSpeed = 0.3f;
public float zoomDampening = 5.0f;
private float xDeg = 0.0f;
private float yDeg = 0.0f;
private float currentDistance;
private float desiredDistance;
private Quaternion currentRotation;
private Quaternion desiredRotation;
private Quaternion rotation;
private Vector3 position;
void Start() { Init(); }
void OnEnable() { Init(); }
public void Init()
{
//If there is no target, create a temporary target at 'distance' from the cameras current viewpoint
if (!target)
{
GameObject go = new GameObject("Cam Target");
go.transform.position = transform.position + (transform.forward * distance);
target = go.transform;
}
distance = Vector3.Distance(transform.position, target.position);
currentDistance = distance;
desiredDistance = distance;
//be sure to grab the current rotations as starting points.
position = transform.position;
rotation = transform.rotation;
currentRotation = transform.rotation;
desiredRotation = transform.rotation;
xDeg = Vector3.Angle(Vector3.right, transform.right);
yDeg = Vector3.Angle(Vector3.up, transform.up);
}
/*
* Camera logic on LateUpdate to only update after all character movement logic has been handled.
*/
void LateUpdate()
{
// If Control and Alt and Middle button? ZOOM!
if (Input.GetMouseButton(2))
{
desiredDistance -= Input.GetAxis("Mouse Y") * Time.deltaTime * zoomRate * 0.125f * Mathf.Abs(desiredDistance);
}
// If middle mouse and left alt are selected? ORBIT
if (Input.GetMouseButton(0))
{
xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
////////OrbitAngle
//Clamp the vertical axis for the orbit
yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
// set camera rotation
desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
currentRotation = transform.rotation;
rotation = Quaternion.Lerp(currentRotation, desiredRotation, Time.deltaTime * zoomDampening);
transform.rotation = rotation;
}
// otherwise if middle mouse is selected, we pan by way of transforming the target in screenspace
else if (Input.GetMouseButton(2))
{
//grab the rotation of the camera so we can move in a psuedo local XY space
target.rotation = transform.rotation;
target.Translate(Vector3.right * -Input.GetAxis("Mouse X") * panSpeed);
target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World);
}
////////Orbit Position
// affect the desired Zoom distance if we roll the scrollwheel
desiredDistance -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs(desiredDistance);
//clamp the zoom min/max
desiredDistance = Mathf.Clamp(desiredDistance, minDistance, maxDistance);
// For smoothing of the zoom, lerp distance
currentDistance = Mathf.Lerp(currentDistance, desiredDistance, Time.deltaTime * zoomDampening);
// calculate position based on the new currentDistance
position = target.position - (rotation * Vector3.forward * currentDistance + targetOffset);
transform.position = position;
}
private static float ClampAngle(float angle, float min, float max)
{
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp(angle, min, max);
}
}
↧
↧
Add collision to 3rd person camera?,Script to stop camera clipping through walls
I have no interest in learning code, I literally just want some script to add collision to my 3rd person camera, as I can't seem to find any online that work.
My current camera script has no collision script, so preferably I'd like some script that I can just tag on the end (current script only deals with movement on the x and y axis to pivot the character around)
Thanks :)
↧
Game dont´t work whene i press play!
Hei, im using Bolt to make a game and i was done with my Movement and Camara stuff,
It worked all well, then i want to go out of fullscreen graph with „shift,Space“
Something happened because i pressed the wrong key and now when I want to play my Lvl My Camara ist freeze.
Normaly the Gras ist going left and right with The Wind but that’s broken
Only if I press a mousebutton and drag my mouse left and right then my gras is working ?
That really strange,
I tryed to make a new „Game“ and importet some old stuff (textures,etc) but even in the new game is this Probleme.
I Hope Someone can help me....
-Niki-
↧
How can i focus the camera on an object i am working on,How to focus camera setting in unity on an object or assets in my scene
I am a complete beginner, and the camera setting of the engine is really a pain I can’t seem to focus it on an object in my scene, is there a way i can focus the camera on the object i am working on, pls this has really been giving me an headache all day,I am a complete beginner, and the camera setting of the engine is on really a pain I can’t seem to focus it on an object in my scene, is there a way i can focus the camera on the object i am working on, pls this has really been giving me an headache all day.
↧
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]
Here is the player controller Script (I deleted some parts that have nothing to do with movement because it is a huge script)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public float MaxSpeed;
public int damage = 1;
public float attackCool;
public int HP;
public float vert;
public float horz;
public float speed;
public float lookx;
public float looky;
public float minx;
public float maxx;
public float sens;
private float x;
private float y;
private float z;
public int forceConst = 50;
private Rigidbody body;
public GameObject cam;
public bool onGround;
public Vector3 crosshare;
public GameObject[] place;
public int select;
private LineRenderer line;
private Text HPdisp;
public int range;
public GameObject maxTarget;
public bool fps;
public Camera thirdPerson;
private Camera firstPerson;
public GameObject preview;
private bool canPlace;
private bool canBreak;
public bool canAttack;
private RaycastHit delete;
private RaycastHit create;
public RaycastHit attack;
public float minDist;
public GameObject Weapon;
private Quaternion weaponOgAngles;
private GameObject overworld;
private GameObject underworld;
// Start is called before the first frame update
void Start()
{
body = GetComponent();
line = cam.GetComponent();
}
// Update is called once per frame
void Update()
{
body.velocity = Vector3.ClampMagnitude(body.velocity, MaxSpeed);
maxTarget.transform.localPosition = new Vector3(0, 0, range);
Cursor.lockState = CursorLockMode.Locked;
//Movement Keys
vert = Input.GetAxis("Vertical");
horz = Input.GetAxis("Horizontal");
x = horz * speed;
z = vert * speed;
//
body.AddRelativeForce(x, 0f, z);
//
if (Input.GetKeyDown(KeyCode.P) && fps)
{
thirdPerson.enabled = true;
firstPerson.enabled = false;
}
if (Input.GetKeyDown(KeyCode.P) & !fps)
{
thirdPerson.enabled = false;
firstPerson.enabled = true;
}
//Look around
lookx += Input.GetAxis("Mouse Y");
lookx = Mathf.Clamp(lookx, minx, maxx);
looky += Input.GetAxis("Mouse X");
cam.transform.eulerAngles = new Vector3(-lookx * sens, looky * sens, 0);
transform.eulerAngles = new Vector3(0, looky * sens, 0);
//Jump
if (Input.GetKeyDown(KeyCode.Space) && onGround == true)
{
body.AddForce(0, forceConst, 0, ForceMode.Impulse);
onGround = false;
}
//Place Blocks
crosshare = cam.GetComponent().ViewportToWorldPoint(new Vector3(0, 0, 0));
preview.transform.position = create.point;
canPlace = Physics.Raycast(crosshare, cam.transform.forward, out create, range);
canBreak = Physics.Raycast(crosshare, cam.transform.forward, out delete, range);
canAttack = Physics.Raycast(crosshare, cam.transform.forward, out attack, range);
if (create.distance == 0)
{
preview.transform.position = maxTarget.transform.position;
}
if (create.distance < minDist)
{
canPlace = false;
}
if (Input.GetMouseButtonDown(1))
{
preview.SetActive(true);
if (canPlace == true)
{
Instantiate(place[select], create.point, cam.transform.rotation);
}
if (create.distance == 0)
{
Instantiate(place[select], maxTarget.transform.position, cam.transform.rotation);
}
Debug.Log(create.distance);
}
//Break them
if (Input.GetMouseButtonDown(0))
{
preview.SetActive(true);
crosshare = cam.GetComponent().ViewportToWorldPoint(new Vector3(0, 0, 0));
if (canBreak == true)
{
if (delete.collider.tag == "Blocks")
{
Destroy(delete.collider);
}
}
}
private void OnCollisionEnter(Collision collider)
{
if (collider.collider.tag == "Walkable" || collider.collider.tag == "Blocks")
{
onGround = true;
}
}
private void OnCollisionStay(Collision collider)
{
if (collider.collider.tag == "Entity" &&
}
[1]: https://drive.google.com/file/d/1WNxfDaLt3XLzKre8tOhAyqrZhnpvKCHV/view?usp=sharing
↧
↧
How to detect if an object takes up a camera's full view?
I learned how to detect if an object is seen by a camera using the guide [here](http://wiki.unity3d.com/index.php?title=IsVisibleFrom). But i'm not really sure how to detect if that object is taking up the full view of the camera.
What I'm trying to do is have an object with an image of a place on it, then when the image fills the player's view and they look away from it, they're teleported to that area. I know how to do all the other aspects of it, just not the camera/viewport detection mentioned in the title.
↧
Camera collision detection.
Hi everybody, i'm in trouble with my Camera script.
Camera rotates around player by using a pivot. assigned as a child of the camera.
This works with 2 arrows (i'm developing this game for mobiles, so they're touch arrows) that allows camera to rotate left and right;
the problem is when the camera goes behind a wall or a huge object and can't see nothing.
I watched for some solution and I see that many developers used the RaycastHit or something similar.
here's my code, the goal is that camera goes close to the pivot when hit a wall.
Can anyone help me?
public Transform target1;
public Transform pivot;
protected ButtonLeft buttonLeft;
protected ButtonRight buttonRight;
public Vector3 offset;
public bool useOffsetValues;
public float rotateSpeed;
private void Start()
{
buttonLeft = FindObjectOfType();
buttonRight = FindObjectOfType();
if (!useOffsetValues)
{
offset = target1.position - transform.position;
}
pivot.transform.position = target1.transform.position;
//pivot.transform.parent = target.transform;
//USE IF U WANT TO DISAPPEAR THE CURSOR
//Cursor.lockState = CursorLockMode.Locked;
//pivot.transform.parent = target.transform;
pivot.transform.parent = null;
// usa questa dopo la costruzione del livello1
//pivot.transform.position = target.transform.position;
}
private void Update()
{
pivot.transform.position = target1.transform.position;
if (buttonLeft.Pressed)
{
pivot.Rotate(0, -90 * Time.deltaTime, 0);
Debug.Log("rotate left");
}
if (buttonRight.Pressed)
{
pivot.Rotate(0, 90 * Time.deltaTime, 0);
Debug.Log("rotate left");
}
Ray ray = new Ray(pivot.transform.position, pivot.transform.position - transform.position);
RaycastHit hit;
/*float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
pivot.Rotate(0, horizontal, 0);
pivot.Rotate(0, horizontal, 0);
Use this to make the camera rotate on Mouse Y axes*/
/*float vertical = Input.GetAxis("Mouse Y") * rotateSpeed;
target.Rotate(vertical, 0, 0); */
//move camera based on the current rotation of the target and the original offset
float desiredYAngle = pivot.eulerAngles.y;
//Use this float to set the x angle of player
float desiredXAngle = pivot.eulerAngles.x;
//Use this rotation only if you want to rotate on Y
//Quaternion rotation = Quaternion.Euler(0, desiredYAngle, 0);
//Use this if u want to rotate up&down on x axes
Quaternion rotation = Quaternion.Euler(desiredXAngle, desiredYAngle, 0);
transform.position = target1.position - (rotation * offset);
//transform.position = target.position - offset;
transform.LookAt(target1);
}
↧
Adding a Vector3 disables movement of camera
I have a smoothed camera that works by taking a direction that you want to view an object from on the unit sphere, multiplying that by an offset, and adding the focus position to that. When at (0,0,0) it works just fine, but the moment it's moved from there, the camera has a bias toward the direction it been moved in. Can I make this not happen?
void RotateSmoothly()
{
//magenta
Vector3 smoothPosOnUnitSphere = Vector3.Slerp((transform.position - Vector3.zero).normalized, desiredPosOnUnitSphere, .1f).normalized;
Vector3 smoothePos = ShiftToFoucusPoint(smoothPosOnUnitSphere);
transform.position = smoothePos;
transform.LookAt(foucusPoint);
}
private Vector3 ShiftToFoucusPoint(Vector3 direction)
{
Vector3 UnUnit = direction.normalized * offset;
return UnUnit + foucusPoint;
}
↧
How can I implement People Occlusion with AR Foundation/AR Core 3.1.3
I am trying to add people occlusion to my AR project with AR Foundation and Core 3.1.3 (Unity 2019.3.15f1). All the tutorials I see use things like AR Occlusion Manager or AR Human Body Manager components, which I can not find with my current version. Am I missing something or is something like people occlusion not supported with my current versions?
↧
↧
How to make enemies go through colliders?
**I'm doing a 2D retro spaceship game.** *And I have colliders around the camera (as a child of the main camera) so the player can't fly away forever, but I want the enemies to like touch the player.* But I don't know how. Any Fixes? ***Thank you!*** :)
,I'm doing a 2D retro spaceship game. And I have colliders around the camera (as a child of the main camera) so the player can't fly away forever, but I want the enemies to like touch the player. But I don't know how. Any Fixes? Thank you!
↧
How to move camera position to player object's direction while having looking at object?
I want to move camera behind my player to look into direction player is looking. This should happen after player movement is stopped. Right now, camera stays only in one direction and moves with Player. The trigger is a **RotateCameraToPlayer** function which is being called from Player script, once player movement is zero. I can receive EulerAngle of Object in Camera Script. I tried lot of options but Camera Rotation is conflicting with **LookAt** function and does not let camera rotate. Can moving position of camera work here? How can we calculate position from angle? I have commented position range needed on different camera angle.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
// Start is called before the first frame update
public GameObject target;
public float smoothSpeed = 3f;
public float smoothRotateSpeed = 30f;
public Vector3 offset = new Vector3(0f,2f,-9f);
public bool LookAtPlayer = true;
public float RotationsSpeed = 30f;
private Vector3 _cameraOffset;
private bool _isRotate = false;
private void LateUpdate() { // if there is a jerk, replace with private void FixedUpdate() {
if(LookAtPlayer == true){
MoveCameraToPlayer();
}
}
public void MoveCameraToPlayer(){
Vector3 desiredPosition = target.transform.position + offset;
Vector3 smoothedPosition = Vector3.Slerp(transform.position, desiredPosition, smoothSpeed * Time.deltaTime);
transform.position = smoothedPosition;
transform.LookAt(target.transform, target.transform.up);
}
public void RotateCameraToPlayer(Vector3 _angle){
Debug.Log(_angle);
// Location value Z > 0(-7) to 180(7) > 180 to 360
// Location value Y 3
// Location value X > 90 (-7) to 270 (7)
}
}
![alt text][1]
[1]: /storage/temp/161622-untitled.jpg
↧
Camera switch with ECS
So I'm relatively new to DOTS and still try to figure out a lot of basic stuff. For my current project I want my camera to switch when i interact with a certain object. The current approach I am using is to just add an Disabled component to the camera that I don't want to use but that does not work constantly for some reason I do not understand. Has anyone a good approach to the usage of multiple cameras in dots or has an Idea why the approach with the disabled component could be inconsistent ?
Here is the code I am using for testing how the switch works.
public class CameraSystem : SystemBase
{
NativeArray entityArray;
EntityQuery m_Group;
CustomSystems.Controlls.Controlls inpt;
bool testInteractionCheck = false;
EndSimulationEntityCommandBufferSystem m_ecb;
protected override void OnCreate()
{
Entity manager = EntityManager.CreateEntity();
EntityManager.AddComponentData(manager, new Tag_SystemUpdate());
m_Group = GetEntityQuery(new ComponentType[] { typeof(Tag_SystemUpdate) });
}
protected override void OnStartRunning()
{
inpt = new CustomSystems.Controlls.Controlls();
inpt.Player.Interact.performed += ctx => testInteractionCheck = true;
inpt.Enable();
m_ecb = World.GetOrCreateSystem();
entityArray = GetEntityQuery(new EntityQueryDesc { All = new ComponentType[] { typeof(Tag_Camera) } }).ToEntityArray(Allocator.Persistent);
}
protected override void OnDestroy()
{
entityArray.Dispose();
}
protected override void OnUpdate()
{
if (testInteractionCheck)
{
JobHandle job = new IJob
{
entities = entityArray,
ECB = m_ecb.CreateCommandBuffer().ToConcurrent(),
disabledComp = GetComponentDataFromEntity(true),
activeTag = GetComponentDataFromEntity()
}.Schedule(m_Group, this.Dependency);
job.Complete();
m_ecb.AddJobHandleForProducer(job);
testInteractionCheck = false;
}
}
struct IJob : IJobChunk
{
public NativeArray entities;
public EntityCommandBuffer.Concurrent ECB;
[ReadOnly]
public ComponentDataFromEntity disabledComp;
[ReadOnly]
public ComponentDataFromEntity activeTag;
public void Execute(ArchetypeChunk chunk, int index, int firstEntity)
{
for (int i = 0; i < entities.Length; i++)
{
if (activeTag.Exists(entities[i]))
{
ECB.AddComponent(index, entities[i]);
ECB.RemoveComponent(index, entities[i]);
}
else
{
if (disabledComp.Exists(entities[i]))
ECB.RemoveComponent(index, entities[i]);
ECB.AddComponent(index, entities[i]);
}
}
}
}
}
↧
How can I destroy gameobject when passing the screen
Hello, Can anyone help me about this code. I can't destroy the gameObject when getting out of the camera screen. I hope can someone figure this out. I'm newbie in programming trying to build my first game app.
public float speed = 10.0f;
private Rigidbody2D rb;
private Vector2 screenBounds;
// Use this for initialization
void Start()
{
rb = this.GetComponent();
rb.velocity = new Vector2(-speed, 0);
screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.x));
}
// Update is called once per frame
void Update()
{
if (transform.position.x < screenBounds.y * 2)
{
void OnBecameInvisible()
{
Destroy(gameObject);
}
}
}
}
↧
↧
SetParrent( ) changes the Y position ?
In my game there is picup and throw funchtion that work on 3D objects like Cubes but when I close and after that I open the project again, that funchtion doesn't work.Instead of working like it shoul the scipt just change the Y position upwards. In order for it to works again I need to recreate the 3D object again , add the scipt and after that everything its fine. Here is the code :
float throwForce = 1500;
Vector3 objectPos;
float distance;
public bool canHold = true;
public GameObject item;
public Transform tempParent;
public bool isHolding = false;
// Update is called once per frame
void Update()
{
distance = Vector3.Distance(transform.position, tempParent.transform.position);
if (distance >= 2f)
{
isHolding = false;
}
//Check if isholding
if (isHolding == true)
{
transform.parent = tempParent;
GetComponent().velocity = Vector3.zero;
GetComponent().angularVelocity = Vector3.zero;
if (Input.GetMouseButtonDown(1))
{
GetComponent().AddForce(tempParent.transform.forward * throwForce);
isHolding = false;
}
}
else
{
objectPos = transform.position;
transform.SetParent(null);
GetComponent().useGravity = true;
transform.position = objectPos;
}
}
void OnMouseDown()
{
if (distance <= 2f)
{
transform.SetParent(tempParent.transform);
isHolding = true;
GetComponent().useGravity = false;
GetComponent().detectCollisions = true;
}
}
void OnMouseUp()
{
isHolding = false;
}
↧
Object rotation and camera view clamping
Hello, how should I clamp object rotation and camera view by Y axis? Camera is attached to GunHead object. I just tried a lot of ways, but it didn't work.
public class G_Camera : MonoBehaviour
{
float sensitivity = 90f;
public GameObject GunHead;
public GameObject GunLegs;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
GunHead.transform.Rotate(0f, mouseX, 0f, Space.World);
GunHead.transform.Rotate(mouseY, 0f, 0f, Space.Self);
GunLegs.transform.Rotate(Vector3.forward * mouseX);
}
}
↧
Why is it red?
![alt text][1]
![alt text][2]
[1]: /storage/temp/161638-unknown.png
[2]: /storage/temp/161640-quack.png
↧