• 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 dama1994 · Oct 06, 2019 at 08:54 PM · cameramoverotate object

Character rotation for Y equal to the camera

My camera with the mouse rotates to a position, and I want my character to turn the same direction only, but for one reason the camera turns faster than the character, I don't know if it's because the results are doubled.

public class MoviemientoPlayer : MonoBehaviour { private Vector3 movement; Rigidbody rb; public int contadorSaltos, totalSaltos; public float velocidadSalto, velocidad, gravity, arriba, abajo; public GameObject cam, puntoSalto, cams;

 public LayerMask layerSuelo;

 void Start()
 {
     rb = GetComponent<Rigidbody>();
     cam = GameObject.Find("Main Camera");
     puntoSalto = GameObject.Find("PuntoSalto");
 }

 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonDown("Jump") && contadorSaltos < totalSaltos)
     {
         rb.velocity = new Vector3(rb.velocity.x, velocidadSalto, rb.velocity.z);
         contadorSaltos++;
     }
 }

 private void FixedUpdate()
 {
     float h = Input.GetAxis("Horizontal");
     float v = Input.GetAxis("Vertical");
     

     if (Physics.OverlapSphere(puntoSalto.transform.position, 0.2f, layerSuelo).Length > 0)
     {
         contadorSaltos = 0;
         velocidadSalto = 14;
     }

         rb.velocity += Vector3.down * Time.deltaTime * gravity;
         Move(h, v);
         Rotacion();

 }

 void Move(float h, float v)
 {
     movement = new Vector3(h, 0, v);
     rb.transform.Translate(movement * velocidad * Time.deltaTime);

 }

 void Rotacion()
 {
     //float he = Input.GetAxis("Horizontal");

     /*  arriba -= velocidadRot * -Input.GetAxis("Mouse X");
       transform.eulerAngles = new Vector3(0.0f, arriba, 0.0f);*/
     //transform.rotation = Quaternion.Euler(transform.rotation.x, cam.transform.rotation.y, transform.rotation.z);
     //transform.Rotate(transform.rotation.x, he, transform.rotation.z);
     arriba += cam.gameObject.GetComponent<ROtacionCamara>().velocidadRot * Input.GetAxis("Mouse X");



     transform.eulerAngles = new Vector3(0.0f, arriba, 0.0f);

 }



public class ROtacionCamara : MonoBehaviour { public float velocidadRot; float arriba, abajo; // Start is called before the first frame update void Start() {

 }

 // Update is called once per frame
 void Update()
 {
     Rot();
 }

 void Rot()
 {
     arriba += velocidadRot * Input.GetAxis("Mouse X");
     abajo -= velocidadRot * Input.GetAxis("Mouse Y");

     //arriba = Mathf.Clamp(arriba, -60f, 90f);
     abajo = Mathf.Clamp(abajo, -90f, 90f);


     transform.eulerAngles = new Vector3(abajo, arriba , 0.0f);
 }

}

}

Sorry i used Google translator

Thank you so much!.

Comment
Add comment · Show 1
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 dama1994 · Nov 16, 2019 at 02:36 PM 0
Share

Hello? I need help :S

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

249 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 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

How can I rotate a sphere so the point is centered in front of the camera 1 Answer

Move the camera to another perspective 0 Answers

if a camera rotates to a point, make something else move? 0 Answers

Rotate grabbed object in relation to cameras Axis 1 Answer

Why the decimals change when I move away from the object? 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