Tank problem. Need help please.

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.

http://dl.dropbox.com/u/20233101/New%20folder%20(2)/WebPlayer/WebPlayer.html

Does anyone know why this would be happening?

Thanks,
Wade

Thats pretty easy to fix actually , just use transform.TransformDirection instead , and it will move along the correct axis.

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 :smile: I’m just using a script I found. I am no where near a scripter.

something you could probably do is switch the controls in “Edit>Project Settings>Input”

I dont have this model , and script and stuff etc, but its looks as if this is the two lines causing you the head ache …

var translation = Input.GetAxis("Vertical") * speed;
transform.Translate (0,0,translation * Time.deltaTime);

try swaping those lines out with something like …

transform.Translate(Vector3.forward);

lemme know if it works or bugged , im just guessing at the moment without actually having anything open in front of me.

transform.Translate (transform.TransformDirection(Vector3.forward)*translation*Time.deltaTime);

Also, you can use transform.forward instead (its the equivalent of transform.TransformDirection(Vector3.forward))

Thank you both, but for some reason Dman, yours did not work.

And willic your code worked, but it still moves the exact same.

This seems to be right.

Is it moving properly you just have your camera and model turned?

Just guessing…

Q

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.

Hmm , this problem is still occuring the next day , its not solved yet?

Lemme know , last night i threw together a quick model and movement script to it here …

http://willcotter.elementfx.com/JaredLocomotor.htm

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.

Are your normals facing the right way?

My normals are facing on the outside of the model (so there is no see through faces), but I didn’t think normals would play a role in moving.

I’ll try and check again. Maybe export the model in .fbx format? Instead of .blend

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

That is what i think is wrong… your object is facing the wrong direction… and the camera too i guess.

But you should be able to test that either by rotating it or by changing the player control settings to a different axis…

But again just guessing

Q

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.

Try calling Translate but instead of using the Z parameter use the X or Y. You should find the axis that relates to your blender model.

Ideally you would then rotate the pivots in blender so that Z works just to stay consistant with unity, but you may find you wont need to.

If blenders anything like max, I ushually need to set the rotation pivot to this:

X: 90 Y: 0 Z: 180

I looked it up in the Scripting Reference

forward is the Blue Axis

up is the Green Axis

right is the Red Axis

So pick the one that fits your model or change your model…

Q