I am making a tank game, and trying to get the mechanics to work. It moves and everything, but not the correct way. If you play it, it’ll pretty much explain it self.
var wheel1 : WheelCollider;
var wheel2 : WheelCollider;
var wheel3 : WheelCollider;
var wheel4 : WheelCollider;
var wheelmid1 : WheelCollider;
var wheelmid2 : WheelCollider;
var smokeL : GameObject;
var smokeR : GameObject;
//Sound variables
private var seconds:float;
var runningSound : AudioClip;
private var playing = "false";
//Speed variables
private var speed = 10.0;
private var speed2 = 0.0;
private var rotate = 50.0;
//MOVEMENT FUNCTION ->
function Update () {
//If one wheel touch's the ground, the tank can move
if (wheel1.isGrounded || wheel2.isGrounded || wheel3.isGrounded || wheel4.isGrounded || wheelmid1.isGrounded || wheelmid2.isGrounded){
seconds = 0;
var translation = Input.GetAxis("Vertical") * speed;
transform.Translate (0,0,translation * Time.deltaTime);
var rotar = Input.GetAxis("Horizontal") * rotate;
transform.Rotate (0,rotar * Time.deltaTime,0);
//If the Vertical axis is pressed...
if(Input.GetAxis("Vertical")){
if(playing == "false"){
audio.Play();
playing = "true";
}
smokeL.particleEmitter.emit = true;smokeR.particleEmitter.emit = true;
speed2=translation;}
else{
speed2=0;
//Si se pulsa el eje horizontal... | If the Horizontal axis is pressed...
if(Input.GetAxis("Horizontal")){
if(playing == "false"){
audio.Play();
playing = "true";
}
smokeL.particleEmitter.emit = true;smokeR.particleEmitter.emit = true;}
//If the tank wheels are not grounded...
else{
audio.Stop();
playing = "false";
smokeL.particleEmitter.emit = false;smokeR.particleEmitter.emit = false;}}
}else{smokeL.particleEmitter.emit = false;smokeR.particleEmitter.emit = false;
if (seconds < 1000){
transform.Translate (0,0,speed2 * Time.deltaTime);
seconds++;
}
audio.Stop();
playing = "false";
}}
I don’t know where to put that at I’m just using a script I found. I am no where near a scripter.
Nah, it turns kind of the way I want it to when you push the side arrows, but if you push the up or down arrows it moves side to side instead of back and forth.
It uses the exact same transform.Translate mentioned above , and is working fine. Im beginning to wonder if maybe yourr axis are not set correctly (this sometimes happens if models were taken from max to unity) but yea, im not sure. I am totally convinced your movement problem lies within the two lines i hi-lited previously though.
EDIT:
PS: if you still cant get it to work and dont mind sharing yer source files , i can edit it up and get it working for you , i am sure.
do that, and make sure your object axes are facing like they should. I also had some issues with moving my tank ‘forward’ but it was because my ‘z’ axis was facing out of the side of the tank… could be that
I can rotate my tank in Unity, but if I try in blender it completely destroys my tank putting meshes in different places, even if I “Center New”. But I don’t think if I rotate it in Unity it has any affect, or at least from what I tried.
Anyways, thank you all for your help.
Wade
(I think I’ll just model another tank (since you will be able to choose different tanks in the game) and just delete the current one)
That happens when things are skinned , linked or what, and have child parent relations somewhere in the stack of modifiers.
If you do rebuild , make sure that before you set up and extras beyond the mesh alone, that you adjust the pivot point to respresent the real world in unity. This seems to be a common mistake amongst exports.