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 jax297 · Jan 03, 2017 at 04:19 PM · controllersphereracing3rd person controller3rd person camera

Guiding a sphere

Hello,

I'm facing a problem I cannot seem to solve, so I thought I'd give forums a try and ask for your help =) Well, I'm trying to guide a sphere. Our player is a Sphere (like any other), and it is forced down the platform by a constant force.

Our spheary player is followed by a camera, meaning, camera is like a 3rd person view (moved back and up, (if we generalize) always looking in direction of spheres velocity).

Now, we want to control this sphere with left and right arrow keys, but we get to several problems - sphere rotates (so we cant use rotation), velocity can't be used (because we are moving straight, and turn sides - example vector goes form 3,0,0 to 0,0,3). We can't use torque either. A problem lies in the sphere itself, I guess - if it were a box, I could use a simple rotation to guide it, but a sphere rotates constantly. And another problem lies in guidance - the camera is always behind the player - pressing W means going straight (by POV) (like in any racing game).

So my question is, how can I control a sphere, turning it left and right (based on the direction it's currently facing)?

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

2 Replies

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

Answer by jmgek · Jan 03, 2017 at 06:08 PM

your looking for vector.Left and vector.Right 90% sure, from what I got in your question.

   Vector3  = transform.TransformDirection(Vector3.right);
  rigidbody.AddForce( myRight * 5 );

And do the same for left.

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 jax297 · Jan 04, 2017 at 10:34 AM 0
Share

And you are 90% correct, so your answer is marked correct. However, I have come to a problem: sphere barely turns at the begining, but when it hits a wall, it turns normally afterwards. And, if it hits the wall by a specific angle, it just looses all orientation (maybe rotation has something to do with it?). Any solutions for that perhaps? Thank you.

avatar image
0

Answer by jax297 · Jan 05, 2017 at 06:54 AM

So, I couldn't make it work with .addforce - the rotation of sphere after hitting a wall were messing up with .right vector, so turning was basically impossible. What I have done, was set up 2 objects, children of camera object. They were positioned left and right of the sphere. Example: When I turn left, I basically add explosion force to sphere, originating at right side

 //START function, get rb of objects positioned left and right of sphere and sphere itself
 Rigidbody leftie = GameObject.Find("leftie").GetComponent<Rigidbody>();
 Rigidbody rightie = GameObject.Find("rightie").GetComponent<Rigidbody>();
 //get sphere rigidbody
 Rigidbody rb = GetComponent<Rigidbody>();
 
 //UPDATE function, we add explosion force to our sphere, originating at leftie and rightie
  if (Input.GetKeyDown("d"))
                 {
                     rb.AddExplosionForce(50f , leftie.transform.position, 1f);
                 }
 
                 if (Input.GetKeyDown("a"))
                 {
                     rb.AddExplosionForce(50f, rightie.transform.position, 1f);
                 }
Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How would I make a 3rd person Controller that only moves up, down, left, and right? 2 Answers

How to get JUST the y rotation of an object? 3 Answers

Racing Turn Movement 1 Answer

How To Improve my Rigid Body Sphere Character Controller 2 Answers

Allign player to walls? 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