The problem is that the ball does not follow the direction the camera is pointed, you can only use the “WASD” and rotate around it. I want it like the “FPS camera” where you look and you can walk in the direction.
Basically you are looking to the left and you still push “W” and it still moves forward, instead of to the left. I need it to “look left then go and travel left”… it’s much easier to see what I’m talking about when you play it, you can clearly see the problem
Here is the Ball’s movement script:
using UnityEngine;
using System.Collections;
public class PlayerControl : MonoBehaviour
{
private GameObject _GameManager;
public Vector3 movement;
public float moveSpeed = 6.0f;
public float drag = 2;
void Start()
{
_GameManager = GameObject.Find("_GameManager");
}
void Update ()
{
Vector3 forward = Camera.main.transform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
Vector3 forwardForce = forward * Input.GetAxis("Vertical") * moveSpeed;
rigidbody.AddForce(forwardForce);
Vector3 right= Camera.main.transform.TransformDirection(Vector3.right);
right.y = 0;
right = right.normalized;
Vector3 rightForce= right * Input.GetAxis("Horizontal") * moveSpeed;
rigidbody.AddForce(rightForce);
}
void OnTriggerEnter (Collider other )
{
if (other.tag == "Destroy")
{
_GameManager.GetComponent<GameManager>().Death();
Destroy(gameObject);
}
else if (other.tag == "Coin")
{
Destroy(other.gameObject);
_GameManager.GetComponent<GameManager>().FoundCoin();
}
else if (other.tag == "SpeedBooster")
{
movement = new Vector3(0,0,0);
_GameManager.GetComponent<GameManager>().SpeedBooster();
}
else if (other.tag == "JumpBooster")
{
movement = new Vector3(0,0,0);
_GameManager.GetComponent<GameManager>().JumpBooster();
}
else if (other.tag == "Teleporter")
{
movement = new Vector3(0,0,0);
_GameManager.GetComponent<GameManager>().Teleporter();
}
}
}
And for the camera I have a basic “SmoothLookAt” and “MouseOrbit” script.
If anyone could tell me how to fix this, it would be really great!
Hmmm, I’m having a lot of trouble following your script to be honest, because your way of thinking is different to mine.
But isn’t the force you’re adding relative to the world co-ordinates rather then your camera co-ordinates? I’d recommend using the rigidbody.velocity rather than addforce.
EDIT: Unless there is a way to use the addrelativeforce and make it relative to your camera rather than your ball.
I want to steer the ball with the mouse, and make the ball move with the “WASD” buttons. Along with a simple line of code that will make me be able to “Jump”
So you don’t want to give the player the option of rotating the camera seperately to the ball? You’d rather them be stuck with not being able to view their surroundings? or not being able to look left and travel right?