Hello there!
This is my second day with Unity, already in love with the powerful API.
So I’m trying to roll a cylinder upon User’s input, is it a good way to do this?
Or is there some optimized way??
Also, the rotation (left and right arrow key inputs) don’t seem to work…am i doing something wrong??
also, please direct me to some good tutorials to understand API of unity and some books(preferable)
PS. Excuse my English ![]()
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
float torque = 100f;
public Rigidbody rb;
public Vector3 eulerAngleVelocity;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKey (KeyCode.UpArrow)) {
rb.AddTorque(transform.up * torque );
}
if (Input.GetKey (KeyCode.DownArrow)) {
rb.AddTorque (transform.up * -torque);
}
/*if (Input.GetKey (KeyCode.LeftArrow)) {
Quaternion deltaRotation = Quaternion.Euler (eulerAngleVelocity * Time.deltaTime);
rb.MoveRotation (rb.rotation * deltaRotation);
}
if (Input.GetKey (KeyCode.RightArrow)) {
Quaternion deltaRotation = Quaternion.Euler (eulerAngleVelocity * Time.deltaTime);
rb.MoveRotation (rb.rotation * deltaRotation);
}*/
}
}