Alright. Today i added some movement control to Taco. It quite easy to setup the collisions and physics, as Unity manage them directly. I mean there's no need to code or import a 2D collision or 2D physic system. it's already there by default, which is great! So i added a Box Collider to the Grass to have a ground for Taco to run on. Then i added a Box collider and a 2D Rigidbody to Taco for him to collide and be able to move (thanks to the rigdbody).
Last i've write some code to make him move when SPACE is pushed down and stop if space is released.
void Update () {
if (Input.GetKeyDown("space")){
Debug.Log("space down : Taco Run.");
isRunning = true;
movement.Set(1, 0);
}
if (Input.GetKeyUp("space")){
Debug.Log("space up : Taco Stop.");
isRunning = false;
movement.Set(0, 0);
}
if (isRunning){
myBody.AddForce(movement * speed * Time.deltaTime);
}
}
You can see the *amazing* result in the video. I'm please at how it goes. it's quite simple to setup those basic components.
No comments:
Post a Comment