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 /
avatar image
0
Question by Aetaugan · Feb 23, 2020 at 10:33 PM · 3dcamera-movementcamera rotateballthird-person-camera

TPS Camera roll ball

Hi everyone,

I'm currently trying to make a rolling ball 'platform' game where you have to finish the route to win.
It looks like this: alt text

Let's me explain how it's working. You can move the camera horizontally by pushing left and right button, you will rotate around the ball. There is the code :

 transform.RotateAround(target.transform.position, (cammovement), Time.deltaTime *smooth);


To move on the ball will follow the camera direction by adding a force when you use top and down button. Here it is (with rbT as the target Rigidbody):

  void RollBall()
     {
         //set force down camera's look direction
         forceDirection = transform.forward;
 
         //remove y force direction for angled camera
         forceDirection = new Vector3(forceDirection.x, 0, forceDirection.z);
 
         if(Input.GetAxis("Vertical") != 0)
         {
       
                 //add force to ball
                 rbT.AddForce(forceDirection.normalized * speed * (Input.GetAxis("Vertical")));
                 
         }
 } 

My first problem was that the camera doesn't follow the ball even it still rotating around. I experimented that we cannot use transform.position and transform.RotateAround in the same code/GameObject.

So I decided to put the Camera inside an Empty GameObject and force the GO to follow the ball using a classic transform position + offset and it's worked pretty well. alt text void LateUpdate() { transform.position = player.transform.position + offset; }

But now I'm trying to manage the collision between the camera and the terrain. I have found a tutorial which explains that easily and I implemented it in, but of course, it contains a transform.position and it's not working on the GO parent (which is not rotating).

There is the experimentation code:

 void Update()
     {
         if(Input.GetAxis("Vertical") != 0)
         {
             desiredCameraPosition = transform.TransformPoint(maxDistance * (Cam.transform.forward * Input.GetAxis("Vertical")));
         }
         //desiredCameraPosition = transform.TransformPoint(dollyDir * maxDistance);
         RaycastHit hit;
         Debug.DrawLine(Cam.transform.position, desiredCameraPosition, Color.green);
 
 
         if (Physics.Linecast(Cam.transform.position, desiredCameraPosition, out hit))
         {
             Debug.Log("1");
             distance = Mathf.Clamp((hit.distance*0.7f), minDistance, maxDistance);
         }
         else
         {
             Debug.Log("2");
 
             distance = maxDistance;
         }
 
        Cam.transform.position = Vector3.Lerp(Cam.transform.localPosition, dollyDir * distance, Time.deltaTime * smooth);
     }

So that is my question. How can I manage the camera rotation and using the transformation position to avoid passing thought the terrain and still be able to rotate around my ball?

capture.png (484.0 kB)
capture.png (1.8 kB)
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

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.

Follow this Question

Answers Answers and Comments

161 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

Related Questions

roll a ball with rotating camera script. when i go back the ball fly 0 Answers

How to make a 3D camera rotate relative to the world? 1 Answer

Screen is 2 cameras with each different properties. 1 Answer

How can i make the camera look up and down through keyboard keys? 2 Answers

Jerky 3rd Person Camera Following Movement and Rotation 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