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 Bormeth · Mar 31, 2011 at 07:43 AM · physicsrotateballrolladdtorque

Making a ball roll and keeping the axis?

This is my script tried enabeling the rigidbody.AddTorgue, but it will then rotate the axis, rather wanna see the texture "roll/rotate" :)

Player is a ball that can jump and move, when moving right i want it to gain momentum.

void Update () { Vector3 horMovement = Input.GetAxis("Horizontal") transform.right Time.deltaTime * PlayerSpeed;

if (Input.GetKeyUp("space") && Physics.Raycast(transform.position, -transform.up, MaxJumps)) { rigidbody.AddRelativeForce(transform.up * PlayerJumpSpeed, ForceMode.Impulse); }

 //rigidbody.AddTorque(Vector3.right * 1 *Time.deltaTime);
 //move player
 transform.Translate(horMovement);

}

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 Meltdown · Mar 31, 2011 at 10:51 AM 0
Share

I'm a bit confused with your question. Surely if you assigned the texture to your ball, and it rolls, the texture should be rotating as well. I don't see how the ball would roll but the texture not.

2 Replies

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

Answer by Bormeth · Apr 02, 2011 at 03:32 PM

Solved it myself :)

Vector3 movement = (Input.GetAxis("Horizontal") -Vector3.left movementSpeed) + (Input.GetAxis("Vertical") Vector3.forward movementSpeed); rigidbody.AddForce(movement, ForceMode.Force);

Did the job :)

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 coastwise · Apr 04, 2011 at 01:10 PM 0
Share

Good job working it out on your own! One comment I have on your method -- and this really depends on the gameplay you're trying to achieve -- is that applying a directional force directly will allow the player to move around in the air (obviously fixable if needed with some checks), whereas adding torque will allow the player to roll the ball directly so it will only get momentum when its on the ground.

avatar image
0

Answer by coastwise · Mar 31, 2011 at 10:58 AM

If your player is a ball, why not simply let it rotate? You could still make it jump upwards if you add a force (rather than a relative force) upwards like so:

void Update () { if (Input.GetKeyUp("space") && Physics.Raycast(transform.position, Vector3.down, MaxJumps)) { rigidbody.AddForce(Vector3.up * PlayerJumpSpeed, ForceMode.Impulse); }

 // move player by letting them roll the ball
 rigidbody.AddTorque(Vector3.right * PlayerRollSpeed * Input.GetAxis("Horizontal") * Time.deltaTime);

}

Try giving that a shot. ('PlayerRollSpeed' should probably be something like 100)

Comment
Add comment · Show 2 · 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 Bormeth · Apr 02, 2011 at 02:46 PM 0
Share

Hmm thx m8 for answering :) But dosnt seem to work now the player wont even move. Used this

     if (Input.Get$$anonymous$$eyUp("space") && Physics.Raycast(transform.position, Vector3.down, $$anonymous$$axJumps))
     {
         rigidbody.AddForce(Vector3.up * PlayerJumpSpeed, Force$$anonymous$$ode.Impulse);
     }

     // move player by letting them roll the ball
     rigidbody.AddTorque(Vector3.right * PlayerRollSpeed * Input.GetAxis("Horizontal") * Time.deltaTime);
avatar image coastwise · Apr 04, 2011 at 01:11 PM 0
Share

Yeah, it wasn't moving for me either until I really cranked the PlayerRollSpeed variable.

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

No one has followed this question yet.

Related Questions

Strange sphere/physics rolling behaviour when scaled 1 Answer

Ball Doesn't Roll Down Hill - Physics Problem 3 Answers

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

How to make a ball that can roll? 2 Answers

Get a free moving ball. 1 Answer


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