Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

make my object face the direction of movement?

$
0
0
I have these two classes here, given to me as part of a project: using UnityEngine; using System.Collections; public class Ball: MonoBehaviour { public float moveSpeed = 30; void Update () { //var dir: Vector3 = Vector3.zero; CharacterController controller = GetComponent(); Vector3 moveDirection = Vector3.zero; moveDirection += Camera.main.transform.up * Input.GetAxis("Vertical"); moveDirection += Camera.main.transform.right * Input.GetAxis("Horizontal"); moveDirection.z = 0; controller.Move(moveDirection * moveSpeed * Time.deltaTime); } } and this one using UnityEngine; using System.Collections; public class GamePad : MonoBehaviour { public float speed = 40; // Update is called once per frame void Update () { transform.Translate (Input.GetAxis("Horizontal")*Time.deltaTime*speed, Input.GetAxis ("Vertical")*Time.deltaTime*speed, 0); } } these two I'm almost certain control movement along the X and Y axis. I have a sphere slightly streched and I want it to rotate it to the direction it is moving. Any ideas? Thanks!

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>