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 superdave1318 · Oct 05, 2013 at 04:32 PM · cameraballlookturnrolling

Mouse look turn with rolling ball

Hi. Im trying to make a rolling ball game where the camera follows the ball and when you look left or right so does the ball. The only problem is that i can't figure out how to do this.

I think the best way to do this is to change the code i have below so that the ball rolls to its forward. then when you press right it rolls to its right, not just the games X,Y,Z.

I am a complete noob to scripting so if you offer a script give the whole thing, not a scrap cuz i will have no idea where to put it.

The ball NEEDS to roll.

The first person that gives me a answer gets his name in the credits for scripting help XD

Comment
Add comment · Show 7
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 robertbu · Oct 05, 2013 at 04:34 PM 0
Share

It is possible to drive the ball based on camera rotation about the ball, but it would be easier to just have the camera follow the ball and have the ball turn. The standard SmoothFollow script will allow your camera to follow the ball. $$anonymous$$aking the ball turn will depend on how you are moving/rolling the ball.

avatar image superdave1318 · Oct 05, 2013 at 04:39 PM 0
Share

its not as much the problem of the camera following it, i have the kinda covered, its just how do i have the ball be able to turn with mouse look AND still be able to roll! If you turn right, and press forward the ball should go forward from where your looking. how do i do that?

avatar image robertbu · Oct 05, 2013 at 04:46 PM 0
Share

It depends on how you are moving/rolling your ball and the relationship of the ball to the camera (i.e. Y height). If your ball is on the same level as the camera you can put this in the script on the ball in the update loop:

 transform.rotation = Quaternion.LookRotation(Camera.main.transform.forward);

If the camera is up on the 'Y' then you may want:

 var v3 = Camera.main.transform.forward);
 v3.y = 0;
 transform.rotation = Quaternion.LookRotation(v3);
avatar image superdave1318 · Oct 05, 2013 at 05:05 PM 0
Share

well i would kinda like the camera to hover over the ball about 5-10 y. Also snippets of code is no use to me seeing as i don't know where to put them. The script for my player so far is:

using UnityEngine; using System.Collections;

public class PlayerController : $$anonymous$$onoBehaviour { public float speed;

 void FixedUpdate ()
 {
     float moveHorizontal = Input.GetAxis("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");
     
     Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
     
     rigidbody.AddForce(movement * speed * Time.deltaTime);
 }

}

Like i said i dont really care for the camera, i can sort that out but what i need is a script that with the mouse turn the ball while ALSO turning where forward, left, right and backward is. so that way when you turn the ball is following where the mouse is.

avatar image robertbu · Oct 05, 2013 at 05:37 PM 0
Share

If I understand you correctly, you need to add this line just below line 8:

 transform.rotation = Quaternion.LookRotation(rigidbody.velocity);
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JamieSinn · Oct 06, 2013 at 11:05 PM

I had this exact problem, this was my fix: Use 3rd person character controller scripts default with unity, they should be under Standard Assets. If you do not have the scripts, go to Assets->Import Package->CharacterController Attach the Character Controller Script to the Ball, and Attach a 3rd Person Camera Controller too.

The ball will not roll, but you will just have to import an fbx file that has animations of rolling on the axis that you want. Attach a Mouse Look Script as well if you want the camera movement on certain axis.

Here is my github showing my game using this: https://github.com/JamieSinn/BinaryBall

Comment
Add comment · Show 4 · 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 JamieSinn · Oct 06, 2013 at 11:07 PM 0
Share

Change the branch to alpha to see this, I forgot to mention it.

avatar image superdave1318 · Oct 07, 2013 at 03:12 PM 0
Share

I know all of this Jamie and i had that before but the ball NEEDS to roll for the reason how the rigidbody moves. As it is a very good answer i need one that has the ball roll. It cant just look like its rolling. Its been done before, i know because i had an asset with such a thing but it would not of worked for many reasons.

avatar image JamieSinn · Oct 07, 2013 at 03:32 PM 0
Share

Is it possible for you to modify the 3rd person script to make it use rigidbody? I personally had the same feeling as you when I tried it, but you may have more success than me at it

avatar image superdave1318 · Oct 08, 2013 at 07:30 PM 0
Share

I would not know how to start! I have been using a lot of scripts off of the internet, Thus the reason i asked in the first place!

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

16 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

Related Questions

Rolling ball camera? 1 Answer

move the object where camera look 0 Answers

Input.mousePosition for new networking 0 Answers

How can i make a 3rd person ball game 0 Answers

using left right keys to turn 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