Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by gosolo2 · Sep 24, 2017 at 03:32 AM · rigidbodyraycastcamera-movementcamera-lookflying

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);

 }


}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by gosolo2 · Oct 01, 2017 at 11:03 PM

NEVER MIND... I found a solution. :) and works fine

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image alberto_ao · Oct 04, 2017 at 04:06 PM 0
Share

I suggest that you post your solution here. It might be useful for other users :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

162 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges