How can I turn a sphere with the mouse while using normal controls to move it?
Hi, I'm new to Unity and scripting and all that, an absolute beginner. The problem that I have is, my player is a sphere with a rigidbody. I'd like to be able to move the sphere like a ball behaves, but rotate it along the X axis with the mouse. The view of the sphere is 3rd person. I've found 3rd person scripts that enable me do that, but then the ball stops spinning and remains stationary like a cube.
This is the player controller script I'm using right now:
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float speed = 15f;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
}
and this is the camera controls I'm using with it: using UnityEngine;
public class CameraController : MonoBehaviour {
public GameObject player;
private Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position - player.transform.position;
}
// Update is called once per frame
void Update () {
transform.position = player.transform.position + offset;
}
}
Any help is appreciated, many thanks.
Your answer
Follow this Question
Related Questions
Backspin of Sphere with Rigidbody 0 Answers
Kinematic sphere doesn't move 1 Answer
Rigidbody sphere slows down but keep rolling 0 Answers
Move Player With Moving Vehicle 1 Answer