I've spent hours on hours looking for the answer and none of them seem to work. I've currently got a rigidbody ball that moves forward, backwards, left and right. To get the camera to follow and rotate with the ball I've created an object that follows the balls positions and is inside of the ball so it's not visible. Now when I turn left on the ball the ball goes left and the camera stays behind the ball but when I press the up arrow it moves right.
I appreciate your time.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestControls : MonoBehaviour {
// Create public variables for player speed, and for the Text UI game objects
public float speed;
//movement control
Vector3 movement;
// Create private references to the rigidbody component on the player, and the count of pick up objects picked up so far
private Rigidbody rb;
// At the start of the game..
void Start ()
{
// Assign the Rigidbody component to our private rb variable
rb = GetComponent();
}
//Updates every frame
void FixedUpdate ()
{
// Set some local float variables equal to the value of our Horizontal and Vertical Inputs
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
// Add a physical force to our Player rigidbody using our 'movement' Vector3 above,
// multiplying it by 'speed' - our public player speed that appears in the inspector
rb.AddForce(movement * speed);
}
}
Thank you
My code:
↧