- Home /
Question by
ibrahimarslan · Feb 11, 2013 at 05:09 PM ·
rotationcontrollerdirectionmove
Rotate Controller and move rotation direction ?
Hi I making a ball game. I need rotate controller and my ball move to rotation direction ?
using UnityEngine;
using System.Collections;
public class Controller : MonoBehaviour {
public CharacterController motor;
public Vector3 direction;
public float speed;
public Transform ball;
public Vector3 ballRot;
public float gravity=5;
public Vector3 camDist;
public Transform cam;
public float smooth;
public Quaternion playerRot;
public float rott;
void Start(){
motor=GetComponent<CharacterController>();
}
void Update(){
cam.position=Vector3.Lerp (cam.position,ball.transform.position-camDist,smooth*Time.deltaTime);
direction=transform.TransformDirection(direction);
rott=Input.GetAxis("Mouse X");
transform.Rotate(0,rott*speed,0);
if(Input.GetKey(KeyCode.W)){
motor.Move(direction*speed*Time.deltaTime);
direction.x=speed;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613092523im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Objects Rotation to modify Objects transform velocity/Direction of travel 1 Answer
How to Convert dir = (a.transform.position - b.transform.position).normalized; to Degrees ? 1 Answer
Help with my Character Controller 1 Answer
Make the player go into the direction I am looking at 0 Answers
Character Model direction 1 Answer