Transform.Translate issue

Ok I have this bit of code to control my players movement, the only problem is that if my character turns then its really messed up because its using world axis or something even though I set it to use the players axis. How???

FinalMove = transform.TransformDirection (Vector3(horizontal,0,vertical));
    
    transform.Translate(FinalMove.x, 0, FinalMove.z, Space.Self);

Leave out the TransformDirection stuff and just use transform.Translate directly.

–Eric

Worked perfect. Thanks!

Ok so I changed back because it looked weird with a dual stick shooter. But after I changed it back something weird happened, when turning left or right the forward/back and side to side movements are messed up, and when I say they are messed up they are reversed. But this only happens when turned to either the left side or the right side and I cant figure it out. Here are my Move and Look functions what’s wrong? Thanks.

function Look(){
if(!autoLook){
ForwardLook = Vector3(Joystick.position.x, 0, Joystick.position.y);
}
else{
ForwardLook = Vector3(LookJoystick.position.x, 0, LookJoystick.position.y);
}
var newForward = Vector3.Slerp(transform.forward, ForwardLook.normalized, maxRotationSpeed * Time.deltaTime);
transform.forward = newForward;
}

function Move(){
percentofpercent = Mathf.Abs(horizontal) + Mathf.Abs(vertical) - 1.0; 
    if (percentofpercent > 0.1) {  
    percentofpercent = percentofpercent * 10000; 
    percentofpercent = Mathf.Sqrt(percentofpercent); 
    percentofpercent = percentofpercent / 100; 
    finalMultiplier = percentofpercent * .25; 
    horizontal = horizontal - (horizontal * finalMultiplier); 
    vertical = vertical - (vertical * finalMultiplier); 
    } 
    vertical = vertical * forwardSpeed;
    horizontal = horizontal * forwardSpeed;
    
    FinalMove = transform.TransformDirection (Vector3(horizontal, 0,vertical));
    
    transform.Translate(FinalMove.x, 0, FinalMove.z, Space.Self);    
    MoveAnim();
    Debug.Log("Side to Side " + FinalMove.x + "; Forward/Back " + FinalMove.z);
}

Bump…

Anyone?

Check out this links;

http://forum.unity3d.com/threads/68837-iPhone-finger-swipe

http://forum.unity3d.com/threads/59003-Touch-Swipe-help

Also there is a really cheap way of implementing the swipe behavior by using XAxis of the mouse.
Here is the script;

var XAxis = Input.GetAxis ("Mouse X");

if(XAxis > 0.5 || XAxis < -0.5)
{
    // Your rotation code goes here...
}

Edit: Sorry this is for your other question

This is sort of a shot in the dark, but I think you need to swap the X axis and the Y axis in your Vector3 declaration. I might be misreading your code, so bear with me.

If what you want to do is to tilt the camera up/down with the joystick, then the Y axis of the joystick should control your X rotation. In 3D space, X is pitch, Y is yaw, and Z is roll. So if you want the Y axis of your joystick to pitch up and down, you need to modify your X rotation axis.

Hope that made sense - it’s sort of a confusing situation.

My apologies if I’m entirely misreading your question.

No see the joysticks are 2d objects on the iphone screen so when used for character movement, there y axis is actually the players z axis (so if you move the joystick up, the player moves forward). Now the problem is, is that if I turn my character to the right or left the movement is reversed so he’ll move backward if I try to move forward, and same with the strafing directions. Thanks for trying to help though.

Oh my gosh, I fixed this and I can’t believe how easy it was, all I had to do was remove transform.TransformDirection and it started working perfectly. Thanks for all the help.