Camera raycast replaces Mouse movement
Hi guys. That is a hard one. How I can replace " Mouse X " and " Mouse Y " ( mouse movement ) by a Raycast coming from the Camera? The camera is the eyes of the ships pilot for pitch and roll. I am trying to create a VR game where the least the player touch the joystick ( xbox controller ) the better. I am trying to free the player ( as much as I can ) of using a joystick, mouse or keyboard. I really appreciate if any one out there could help me. Thanks.
using UnityEngine; using System.Collections;
public class flightControl : MonoBehaviour {
private Rigidbody mainRigidbody;
private float roll;
private float pitch;
private bool yawLeft;
private bool yawRight;
void Start()
{
mainRigidbody = GetComponent<Rigidbody>();
}
public float pitchSens = 1f;
public float yawSens = 1f;
public float rollSens = 1f;
void FixedUpdate ()
{
if(Input.GetKey("tab"))
{
//do nothing
}
else
{
yawLeft = Input.GetKey("a");
yawRight = Input.GetKey("d");
pitch = Input.GetAxis("Mouse Y");
roll = Input.GetAxis("Mouse X");
//Debug.Log(roll);
mainRigidbody.AddRelativeTorque(pitch * pitchSens, 0, -roll * rollSens);
if(yawLeft)
{
mainRigidbody.AddRelativeTorque(0, -1 * yawSens, 0);
}
if(yawRight)
{
mainRigidbody.AddRelativeTorque(0, 1 * yawSens, 0);
}
}
}
public float getPitch()
{
return pitch;
}
public float getRoll()
{
return roll;
}
}
I have this script bellow where the ship follows where the camera is pointing the problem with this script... I have just one speed and no control on the ships rigidbody. It will be nice if I could combine the 2 scripts or have a solution for the first one.
using System.Collections; using UnityEngine;
public class RiftCameramoves : MonoBehaviour {
public float speed = 1;
// Use this for initialization
private void Start()
{
}
// Update is called once per frame
private void Update()
{
transform.Translate(Camera.main.transform.forward * Time.deltaTime * speed, Space.World);
}
}
Answer by gosolo2 · Oct 01, 2017 at 11:03 PM
NEVER MIND... I found a solution. :) and works fine
I suggest that you post your solution here. It might be useful for other users :)
Your answer
Follow this Question
Related Questions
getting Jittery movement on camera when player rotating and moving in same time 0 Answers
When attaching my custom camera script camera shakes when player starts to move fast. 0 Answers
How to add rigid body forces and collision detection to SimpleCameraController 2 Answers
How can I move an object in the direction another object is facing. 1 Answer
Strange Question about Stickers 0 Answers