- Home /
Question by
Michael 16 · May 17, 2011 at 03:52 PM ·
directionballrolling
Spherical legs rolling where that enemy go and not looking
Sorry if its a stupid question...
In my game there is an enemy with a ball instead of legs. The enemy can look at me and go to different directions. How I can make the ball rolls allways to the direction he go and not the direction he look and roll accordingly to the speed of the enemy?
The ball attached to the enemy and don't have any code / rigidbody.
Comment
Answer by Tommy · May 17, 2011 at 04:45 PM
Maybe something like this can get you started?
function Update () {
if (Input.GetKey ("up")) {
rigidbody.AddForce (Vector3.-down * 10);
}
if (Input.GetKey ("down")) {
rigidbody.AddForce (Vector3.down * 10);
}
if (Input.GetKey ("left")) {
rigidbody.AddForce (Vector3.-right * 10);
}
if (Input.GetKey ("right")) {
rigidbody.AddForce (Vector3.right * 10);
}
}
Ofcourse then you'll need to add a rigidbody to it.
The ball just flying around. The ball needs to stay under the enemy because this is hes legs... One more thing: the ball don't need to roll when I click on a key, the enemy moves by himself...