# How to apply gravity and collision to character controller

Hi, I’m pretty new in using unity. I have been trying to make simple a top down shooter game.

The script I’m using to move the tank around is this

``````#pragma strict
var Tank:Transform;
//Movement
var acceleration: float=1;
var maxSpeed: float;
//Rotation
var rAcc: float=0;
var maxTurnspeed: float=100;
function Start () {

}

function Update () {
//Tank movement
Tank.Translate(1*acceleration*Vector3.forward*Time.deltaTime);
if (Input.GetAxisRaw("Vertical")==1){
if (acceleration < maxSpeed) {
acceleration += 1;
}
}
if (Input.GetAxisRaw("Vertical")==-1){
if(acceleration>-maxSpeed){
acceleration-=1;
}
}
if (Input.GetButton("Jump") == true){
if(acceleration > 0){
acceleration = acceleration - 1;
}
if(acceleration < 0){
acceleration = acceleration + 1;
}
}
//Tank rotation
Tank.Rotate(rAcc*Vector3.up*Time.deltaTime);
if (Input.GetAxisRaw("Horizontal")==1){
Tank.Rotate(maxTurnspeed*Vector3.up*Time.deltaTime);

}
if (Input.GetAxisRaw("Horizontal")==-1){
Tank.Rotate(maxTurnspeed*Vector3.down*Time.deltaTime);
}
}
``````

Is there a simple way to make gravity affect the tank?

My second question is about the tank going trough everything, it has character controller attached to it, but it doesn’t collide with anything. The hitbox seems to be capsule.

First Question:

I should try: tank.rigidbody.useGravity to true by coding:

tank.rigidbody.useGravity = true;

Of course you can also set it to false if u want.
You also have to have a rigidbody to the tank attached.

Second Question:

You should take a look at the other gameobjects your tank is driving through. Look if they got a collider without the is-trigger-box ticked on.
Good luck:)