- Home /
Question by
Haobo38 · Oct 19, 2021 at 08:30 AM ·
cameravreventsystemphysics.raycast
event triggered by the wrong camera
after the override of input in order to use the htc vive controllers :
public class VRCanvasInput : BaseInput
{
public Camera eventCamera = null;
public SteamVR_Input_Sources m_TargetSource;
public SteamVR_Action_Boolean m_ClickAction;
protected override void Awake()
{
GetComponent<BaseInputModule>().inputOverride = this;
}
public override bool mousePresent
{
get
{
return true;
}
}
public override bool GetMouseButton(int button)
{
return m_ClickAction.GetState(m_TargetSource);
}
public override bool GetMouseButtonDown(int button)
{
return m_ClickAction.GetStateDown(m_TargetSource);
}
public override bool GetMouseButtonUp(int button)
{
return m_ClickAction.GetStateUp(m_TargetSource);
}
public override Vector2 mousePosition
{
get
{
return new Vector2(eventCamera.pixelWidth / 2, eventCamera.pixelHeight / 2);
}
}
}
I want to create a physics pointer attaching the following script :
public class PhyCamPointer : MonoBehaviour
{
public float defaultLength = 3.0f;
private LineRenderer lineRenderer = null;
public GameObject m_Dot;
public Camera m_Camera= null;
private void Awake()
{
lineRenderer = GetComponent<LineRenderer>();
m_Camera = GetComponent<Camera>();
}
private void Update()
{
UpdataLength();
}
public Camera GetCamera()
{
if (m_Camera == null)
print("failded to get camera");
return m_Camera;
}
public Vector3 GetDotPosition()
{
return CalculateEnd();
}
private void UpdataLength()
{
lineRenderer.SetPosition(0, transform.position);
lineRenderer.SetPosition(1, CalculateEnd());
//print("laiser end dot position" + CalculateEnd().x + CalculateEnd().y);
}
private Vector3 CalculateEnd()
{
RaycastHit hit = CreateForwardRaycast();
Vector3 endPosition = DefaultEnd(defaultLength);
if (hit.collider)
endPosition = hit.point;
m_Dot.transform.position = endPosition;
return endPosition;
}
private RaycastHit CreateForwardRaycast()
{
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Physics.Raycast(ray, out hit, defaultLength);
return hit;
}
private Vector3 DefaultEnd(float length)
{
return transform.position + (transform.forward * length);
}
}
for the eventSystem and physicsPointer (child of right controller )
after such configuration, when i lanch the project, the ray is always casted from the camera of the cameraRig( the prefab in steamVR) which means i cant select the objects with the controller but with the headset ( like a look select but not a controller select ) can someone tell me how can i set it to the right camera. Thanks a lot
capture.png
(65.6 kB)
eventsystem.png
(61.3 kB)
Comment
Your answer
Follow this Question
Related Questions
HUD wont show with Cardboard 0 Answers
How to use Target Eye Unity 5.2.2p1? 0 Answers
Google cardboard - Wrong cameras? 0 Answers