Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Mar 19, 2013 at 01:32 PM by Fattie for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ardtrav · Mar 17, 2013 at 02:34 PM · cameraobjectdirection

How to change forward direction of ball to where camera is facing?

Hi,I know there are already a number of questions related to object facing camera look,but none have quite the answers for me though,I am still a newbie though so I must have not really understood them unfortunately,maybe with a little detail from my side of story could help me. Okay,so i got the camera to follow my rolling object,n got the mouse look script,first ill show the rolling ball script: #pragma strict

 function Start () {
 }
 
 var PlayerJumpSpeed : float = 5.0;
 var MaxJumps : float = 30.0;
 var PlayerRollSpeed : float = 100.0;
 var rotationSpeed : float = 30.0;
 var maxRadiansDelta : float = 30.0;
 var amount : float = 0.30;
 var movementSpeed : float = 20.0; /* Block speed */
 
 
 function FixedUpdate () 
 {
     var movement = (Input.GetAxis("Horizontal") * -Vector3.left * movementSpeed)+(Input.GetAxis("Vertical") * Vector3.forward * movementSpeed);
     rigidbody.AddForce(movement, ForceMode.Force);
     // move player by letting them roll the ball
       //var rot :float = Input.GetAxis("Horizontal") * Time.deltaTime;
       //rigidbody.transform.Rotate(0,rot,0);
       //Vector3.RotateTowards(Vector3.left,Vector3.left,maxRadiansDelta,maxMag);
     //rigidbody.AddForce(Vector3.Cross(Vector3.left,Vector3.forward) * amount);
      
     var torque = Vector3(Input.GetAxis("Vertical"), 0, -Input.GetAxis("Horizontal"));
     //torque = Camera.main.transform.TransformDirection(torque);
     //torque.y = 0;
     rigidbody.AddTorque(torque.normalized*movementSpeed);
      
     
     /*if (Input.GetKeyUp("space") && Physics.Raycast(transform.position, Vector3.down, MaxJumps)) 
     {
     
         rigidbody.AddForce(Vector3.up * PlayerJumpSpeed, ForceMode.Impulse);          
     }*/
 }

this is the camera follow script: /* This camera smoothes out rotation around the y-axis and height. Horizontal Distance to the target is always fixed.

 There are many different ways to smooth the rotation but doing it this way gives you a lot of control over how the camera behaves.
 
 For every of those smoothed values we calculate the wanted value and the current value.
 Then we smooth it using the Lerp function.
 Then we apply the smoothed values to the transform's position.
 */
 
 // The target we are following
 var target : Transform;
 // The distance in the x-z plane to the target
 var distance = 10.0;
 // the height we want the camera to be above the target
 var height = 5.0;
 // How much we 
 var heightDamping = 2.0;
 var rotationDamping = 3.0;
 var cameraObject : GameObject;
 // Place the script in the Camera-Control group in the component menu
 @script AddComponentMenu("Camera-Control/Smooth Follow")
 
 
 function LateUpdate () {
     // Early out if we don't have a target
     if (!target)
         return;
     
     // Calculate the current rotation angles
     var wantedRotationAngle = target.eulerAngles.y;
     var wantedHeight = target.position.y + height;
         
     var currentRotationAngle = transform.eulerAngles.y;
     var currentHeight = transform.position.y;
     
     // Damp the rotation around the y-axis
     currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
 
     // Damp the height
     currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
 
     // Convert the angle into a rotation
     var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
     
     // Set the position of the camera on the x-z plane to:
     // distance meters behind the target
     transform.position = target.position;
     transform.position -= currentRotation * Vector3.forward * distance;
 
     // Set the height of the camera
     transform.position.y = currentHeight;
     
     // Always look at the target
     //transform.LookAt (target);
 }

and both scripts were of course obtain from parts of code of other places i searched. Now the mouse look code: using UnityEngine; using System.Collections;

 [AddComponentMenu("Camera-Control/Mouse Look")]
 public class MouseLook : MonoBehaviour {
 
     public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
     public RotationAxes axes = RotationAxes.MouseXAndY;
     public float sensitivityX = 15F;
     public float sensitivityY = 15F;
 
     public float minimumX = -360F;
     public float maximumX = 360F;
 
     public float minimumY = -60F;
     public float maximumY = 60F;
 
     float rotationY = 0F;
 
     void Update ()
     {
         if (axes == RotationAxes.MouseXAndY)
         {
             float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
             
             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
             rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
             
             transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
         }
         else if (axes == RotationAxes.MouseX)
         {
             transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
         }
         else
         {
             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
             rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
             
             transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
         }
     }
     
     void Start ()
     {
         // Make the rigid body not change rotation
         if (rigidbody)
             rigidbody.freezeRotation = false;
     }
 }

So now,with all these in place i need help of how to make the ball object turn,or its forward direction faces according to where the camera faces,thank you,it would help for a detailed explanation,im still new.

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 Last_A · Jul 20, 2017 at 01:09 AM 0
Share

https://www.youtube.com/watch?v=blO039OzUZc&t=394s i used this camera but then u lose rotation option of sphere

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Typecasting Camera to Object for ObjectField 3 Answers

Change characters direction using camera view 0 Answers

How can I change camera when colliding with "X" object? 1 Answer

Measuring XYZ coordinates in Unity vs in real life. 1 Answer

How do you position an object relative to the camera? 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