I want to set z Axis turn based on camera like my camera is facing on a direction and i want to move my ball on camera direction and turn left and right based on camera direction
#pragma strict
var _camera : Transform;
var _ballObject : Transform;
var _speed : float = 5;
var _turnSpeed : float = 10;
private var forceDirection : Vector3 ;
function Start ()
{
}
function Update ()
{
//transform.position = _ballObject.position;
if(Input.GetAxis("Vertical") != 0 )
{
Rolling();
}
// _camera.transform.Rotate = _ballObject.transform.Rotate((Vector3.up * Input.GetAxis("Horizontal") * _turnSpeed), Space.World);
}
function Rolling()
{
forceDirection = _camera.transform.forward;
//remove y force direction for angled camera
forceDirection = new Vector3(forceDirection.x, 0, forceDirection.z);
//add force to ball
_ballObject.GetComponent.<Rigidbody>().AddForce(forceDirection.normalized * _speed * (Input.GetAxis("Vertical")));
}
ball can move forward based on camera direction but no right left Turn