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 /
  • Help Room /
avatar image
0
Question by omtturan2 · Dec 09, 2020 at 01:38 PM · ballthird-person

Thitd Person Rolling Ball?,

HOW TO GET THIS MOVEMENT AND CAMERA?

So basically I want to do a ball movement and camera like the in the new plants vs. zombies game. EXAMPLE VIDEO: link text

The problem is that I want the ball to roll when moving which automatically changes its axis so my horizontal and vertical input dont move the ball into the directions they should. Also I want to rotate the camera around the ball like in a typical 3rd Person Game. I cant use the ball as a parent to the camera otherwise the camera would rotate like crazy...

This is my movement:

 public class BallMove : MonoBehaviour
 {
     public float speed;
     public float MouseSensitivity;
     private Rigidbody rb;
    
     
     // Start is called before the first frame update
     void Start()
     {
         rb = GetComponent<Rigidbody>();
         
     }
 
     private void Update()
     {
         if (Input.GetAxis("Mouse X") > 0)
         {
             //Code for action on mouse moving right
             transform.Rotate(0, MouseSensitivity * Time.deltaTime, 0);
         }
 
         if (Input.GetAxis("Mouse X") < 0)
         {
             //Code for action on mouse moving left
             transform.Rotate(0, -MouseSensitivity * Time.deltaTime, 0);
         }
 
         //Press Space to Jump
         if (Input.GetButtonDown("Jump"))
         {
             rb.AddForce(new Vector3(0, 8, 0), ForceMode.Impulse);
 
         }
 
         //Press Shift to increase Speed
         if (Input.GetKeyDown(KeyCode.LeftShift))
         {
             speed = speed * 2;
 
         } else if (Input.GetKeyUp(KeyCode.LeftShift)) {
             speed = speed / 2;
         }
 
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
        
         float vertical = Input.GetAxis("Vertical") * speed;
         float horizontal = Input.GetAxis("Horizontal") * speed;
 
         //Movement when pressing WASD
         rb.AddForce(transform.forward * vertical);
         rb.AddForce(transform.right * horizontal);
 
         //Setting a Speedlimit so it doesnt accelerate infinetly
         if (rb.velocity.magnitude > speed)
         {
             rb.velocity = rb.velocity.normalized * speed;
         }
      
     }
 }

I tried giving both the ball and the camera the same parent and adding the movement to the parent. So the camera rotates around a parent that doesnt roll like a ball and the ball uses the parent´s axis...BUT to add force the parent needs a rigidbody and the ball too otherwise it would not roll. I tried this but the ball behaves very weird and instantly gets pushed to the side disabling all movement. I found out in another blog that a parent and a child with each having a rigidbody cant work out well. I tried a million other things but it didnt work but as you can the in the video it is possible! Thank you for your help!

,

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

212 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

Related Questions

Third person game hit a ball 0 Answers

How to rotate the camera? 0 Answers

How do I fix script? error CS1525 Unexpected Symbol `ballObject' expecting `)', `,',`;',`[', or `=' . 0 Answers

How to make bounce ball always the same height 1 Answer

I need help making a ball accelerate 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