0
Beantwortet

First person and orbit controls problem

wujustin809 vor 2 Jahren in realvirtual.io Starter and Professional aktualisiert von Support vor 2 Jahren 4

Hey team! I just had a quick question regarding the cameras in the game4automation demo scene. 


I am trying to turn on the first person camera provided to us but unfortunately it is not working properly. What I want is the user to be able to walk around the game4automation scene in first person view and also have the full functionality of the normal orbit controls the scene currently has. May you please give me some instructions on how to do this? There seems to be no documentation about this. If the above is not possible, how can one turn on the first person controls and once a camera is clicked such as 1 or 2, orbit controls are turned on while first person is turned off. Then there needs to be an option to turn first person controls back on again. This is taking me much longer than it should where I believe it should be a simple fix on my end so I truly appreciate the help. Thank you in advance!

Antwort

Antwort
Beantwortet

1) We did not planned to support jumps. You could build your own logic by changing Assets/game4automation/private/RuntimeUI/FirstPersonController.cs

2) You could use this function and your own custom script for doing this:

https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html

NICHT GUT, ICH BIN UNZUFRIEDEN.
Zufriedenheit von wujustin809 vor 2 Jahren

Hey, some more clarification below!

1. I believe I was able to figure out how to switch between first person and orbit controls. But, in the first person view, it does NOT jump for some reason. How to fix this and make it jump when the space bar is pressed?

2. I am trying to get an option where if the user double right clicks on a game object, the camera zooms in and only focuses on this object. For example, if I double right click on the robot arm, the camera will zoom into this robot arm and focus on it, the user can still rotate the camera only around this robot arm object. How to add this? Will greatly appreciate your help.

Antwort
Beantwortet

1) We did not planned to support jumps. You could build your own logic by changing Assets/game4automation/private/RuntimeUI/FirstPersonController.cs

2) You could use this function and your own custom script for doing this:

https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html

Ah I see! For the second question, will the custom script go into the Main Camera or FirstPersonController provided by game4automation or my object? And what public variables would be required? I have attempted various scripts but all does not seem to be working. I look forward to your response. Please see below:

Script 1:

using UnityEngine;

public class ZoomEffect : MonoBehaviour {
Vector3 groundCamOffset;
Vector3 camTarget;
Vector3 camSmoothDampV;

public Camera mainCamera;

private Vector3 GetWorldPosAtViewportPoint(float vx, float vy)
{
Ray worldRay = mainCamera.ViewportPointToRay(new Vector3(vx, vy, 0));
Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
float distanceToGround;
groundPlane.Raycast(worldRay, out distanceToGround);
Debug.Log("distance to ground:" + distanceToGround);
return worldRay.GetPoint(distanceToGround);
}

void Start() {
Vector3 groundPos = GetWorldPosAtViewportPoint(0.5f, 0.5f);
Debug.Log("groundPos: " + groundPos);
groundCamOffset = mainCamera.transform.position - groundPos;
camTarget = mainCamera.transform.position;
}

void Update() {
if (Input.GetMouseButtonDown(0)) {
// Center whatever position is clicked
float mouseX = Input.mousePosition.x / mainCamera.pixelWidth;
float mouseY = Input.mousePosition.y / mainCamera.pixelHeight;
Vector3 clickPt = GetWorldPosAtViewportPoint(mouseX, mouseY);
camTarget = clickPt + groundCamOffset;
}

// Move the camera smoothly to the target position
mainCamera.transform.position = Vector3.SmoothDamp(
mainCamera.transform.position, camTarget, ref camSmoothDampV, 0.5f);
}
}

Script 2:

using System.Collections;

using UnityEngine;

public class ZoomEffect : MonoBehaviour
{
public float movespeed = 35.0f;
//you need to say how far from the object the camera will stop
public float minimumDistanceFromTarget = 5f;
public GameObject targetobject;
private bool movingtowardstarget = false;

// Use this for initialization
void Start()
{
}

// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(1))
{
if (movingtowardstarget == true)
{
movingtowardstarget = false;
}
else
{
movingtowardstarget = true;
}
}

if (movingtowardstarget)
{
movetowardstarget(targetobject);
}
}

public void movetowardstarget(GameObject target)
{
if(Vector3.Distance(transform.position, target.transform.position) > minimumDistanceFromTarget) //we move only if we are further than the minimum distance
{
transform.position = Vector3.MoveTowards(transform.position, target.transform.position, movespeed * Time.deltaTime);
} else //otherwise, we stop moving
{
movingtowardstarget = false;
}
}
}

-2

Hi, it seems that you need to get some Unity basic development knowledge. There is a lot of stuff on the internet. 


Please understand that we can't provide for free development support and service. If we should help you with a training or a custom support package, then send us an email to info@realvirtual.io