- Home /
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
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.
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?
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);
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.
If I understand you correctly, you need to add this line just below line 8:
transform.rotation = Quaternion.LookRotation(rigidbody.velocity);
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
Change the branch to alpha to see this, I forgot to mention it.
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.
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
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
Follow this Question
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