Hey,
I am trying to use the W and S key in order to control a cube which I am just using for a demo… Below is the code I have found which allows me to use the mouse to move the cube and hit the Sphere… How can I make it so the cube is moved with WASD?
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
public class SphereMovement : MonoBehaviour
{
float ZSpeed = 1.0f;
float XSpeed = 1.0f;
void Start()
{
rigidbody.freezeRotation = true;
rigidbody.drag = 5.0f;
Physics.maxAngularVelocity = 100.0f;
}
void Update()
{
rigidbody.AddForce(new Vector3(Input.GetAxis("Mouse X") * XSpeed
0, Input.GetAxis ("Mouse Y") * ZSpeed), ForceMode.Impulse);
}
void OnCollisionEnter(Collision other)
{
if(other.rigidbody)
{
if(!other.gameObject.GetComponent<ConstantForce>())
other.gameObject.AddComponent<ConstantForce>();
else
other.rigidbody.constantForce.force = rigidbody.velocity;
}
}
}
Thanks,
John