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 /
avatar image
0
Question by static_cat · Oct 24, 2012 at 06:19 AM · forceballtorquerollaxes

Another Ball Rolling Game Question

I've read a bunch of the questions others have posted here about scripts that you can use to control a ball and make it roll around, and while several of them have helped, I've run into an issue that I haven't yet seen addressed (though maybe I just don't know where to look).

My ball has a reflective material, so the base texture can be seen rolling but the reflection of the surroundings doesn't move, obviously. What I'd like is to be able to use WASD to roll the ball using physics, but the different approaches I've tried all suffer from the same flaw: once I get the ball rolling in one direction, its axes all roll with it, and my controls depend on the axis orientation to tell the engine which way to apply the force/torque, depending on the script I use. Thus, what is up one moment becomes left or back the next moment, and the game is not very playable like that.

Is there either a way to fix the axes while still allowing the ball to give the appearance of rolling, or an alternate way to apply force to the ball that will not require me to reference the axes? I suspect perhaps the Transform.TransformDirection function is what I'm looking for, but I haven't been able to implement it without getting serious errors.

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 static_cat · Oct 24, 2012 at 05:32 AM 0
Share

I'll post my script in just a moment, for your reference.

1 Reply

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

Answer by static_cat · Oct 24, 2012 at 07:30 AM

I went back to copy my script to this question, and noticed that a change I'd made in the script right before I asked this question was producing an error in Unity. So, I went to correct it, and realized some of my script was missing entirely. Still not sure what happened to it, but when I rewrote it til it ran, suddenly my script does EXACTLY what I wanted it to do. Crazy. I couldn't tell you what I was doing wrong, which is unfortunate, I'd like to have gained something from this headache, but at least the controls for the ball work right. I'll post the script I wound up with in the end in the event someone else winds up with the same problem I did.

 function Update () {
 
     if (Input.GetAxis ("Horizontal")>0)
     {
         rigidbody.AddForce(speed, 0, 0);
     }
     if (Input.GetAxis ("Horizontal")<0)
     {
         rigidbody.AddForce(-speed, 0, 0);
     }
     if (Input.GetAxis ("Vertical")>0)
     {
         rigidbody.AddForce(0, 0, speed);
     }
     if (Input.GetAxis ("Vertical")<0)
     {
         rigidbody.AddForce(0, 0, -speed);
     }
 }

I just defined a "speed" variable, which I can tweak in-game later on til it's just right, and viola.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I move my object through physics with my keyboard? 1 Answer

Problem with joystick movement 1 Answer

Ball Rotating Help 0 Answers

add torque at position 2 Answers

Figuring out the correct amount of torque to apply? 2 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