• 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
1
Question by Orid · Mar 15, 2014 at 09:46 PM · ball

Make hamster inside ball rotate to face direction of travel?

I'm trying to make a 3D hamster mesh placed inside of a separate ball mesh rotate to face the direction the ball is traveling in. I'm new to coding in javascript.

The ball rolls exactly how I want it to, I just want to put the hamster object in it and make the hamster turn to face in whatever direction the ball is rolling in.

1) Does the hamster need to have a mesh collider with gravity, rigidbody, etc?

2) I tried using LookAt, the follow transform, RotateAround, just about everything I can think of, including solutions given to similar questions on this forum. Spent 8 hours trying to figure it out. Help appreciated :)

Ball movement script (if this helps):

 var up = 15;
 var down = -15;
 var east = -15;
 var west = 15;
 var cam : Transform;
 var jumpSpeed = 500;
 
 function Jump()
     {
         rigidbody.AddForce(Vector3.up * jumpSpeed);
     }
 
 // Update is called once per frame
 function Update () {
 
 
 
 if (Input.GetKey("up"))
 {
     rigidbody.AddForce(cam.transform.forward * up);
 }
 
 if (Input.GetKey("down"))
 {
     rigidbody.AddForce(cam.transform.forward * down);
 }
 
 if (Input.GetKey("left"))
 {
     rigidbody.AddForce(cam.transform.right * east);
 }
 
 if (Input.GetKey("right"))
 {
     rigidbody.AddForce(cam.transform.right * west);
 }
 
 if(Input.GetKey("space")) 
         {
             Jump();
             
         }
 


 
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 Fattie · Mar 15, 2014 at 10:29 PM 0
Share

nice question

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Mar 15, 2014 at 10:20 PM

I'd probably simulate the positioning of the hamster in the ball rather than try and use Physics. Colliders are one sided, so you'd have to create a second 'ball' with the normal reversed inside the outer ball just as a starting point if you wanted to get real physics working. And I fear there would be a lot more issues. You could start with something like this in Update():

 transform.position = ball.position + Vector3.down * someValue;

If you constructed your hamster correctly (front of the hamster facing positive 'z' with the rotation is (0,0,0), you should be able to get him to face the correct direction by:

 transform.rotation = Quaternion.LookRotation(ball.rigidbody.velocity);
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 Fattie · Mar 15, 2014 at 10:29 PM 0
Share

RIght .. is it this simple:

(1) put the hamster a the same position as the center of the ball. ($$anonymous$$aybe offset up or down a little.)

(2) point the hamster, quite simply, in whatever the current velocity of the ball is.

(OP - that is exactly what Robert is saying above :) )

It's not totally clear what the OP is asking, Robert - I wonder if it's that simple?

Note - exactly as R says, forget physics here, it's irrelevant.

(You'd essentially just have your animation studio do anims of him "as the ball is speeding up" and "as the ball is slowing down" -- you know, sort of getting ahead/behind the roll a little. Same deal for turning. Just blend those in. And generally make his run animation speed go with the ball speed. It would be a real tour de force for a top animator.)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Simulating Marble Blast Gold: A script to make a character as a marble roll forward, mouse turns screen? 2 Answers

Whats the JavaScript for making a ball roll? 2 Answers

Simple Collision Deflection (Pong) 1 Answer

How to show a scored goal? 1 Answer

Simple peggle type ball physics 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