# Character rotation problem

Hi, I’ve posted about this once a month ago and haven’t got any helpful responses so here I come again… My character can only move along set axis’ and I want to change it. I mean, when I press forward, it moves along z axis and I want it to move towards the direction of the camera. I’d really apreciate any kind of help… I’ve been stuck for ages. Here’s the character control script:
PlayerMovement

``````using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public float speed = 6f;

Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
float camRayLenght = 100f;

void Awake()
{
anim = GetComponent<Animator>();
playerRigidbody = GetComponent<Rigidbody> ();

}
void FixedUpdate()
{
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");

Move (h, v);
Turning ();
Animating (h,v);

if(Input.GetButton("Vertical"))
{
transform.rotation = Quaternion.Euler(0,Camera.main.transform.eulerAngles.y,0);

}
else
{
transform.Rotate(0,Input.GetAxis("Horizontal") * v * Time.deltaTime, 0);
}
}

void Move (float h, float v)
{

movement.Set (h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
playerRigidbody.MovePosition (transform.position + movement);

}
void Turning()
{
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);

RaycastHit floorHit;

if(Physics.Raycast (camRay, out floorHit, camRayLenght, floorMask))
{
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;

Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
playerRigidbody.MoveRotation (newRotation);

}
}
void Animating(float h, float v)
{
bool walking = h != 0f || v != 0f;
anim.SetBool ("IsWalking", walking);
bool slide = Input.GetButton("Jump");
anim.SetBool ("Sliding", slide);
}
}
``````

``````// to get the direction of a source to a target, in your case a camera:
Vector3 direction = (targetTransform.position - sourceTransform.position).normalized;

//then you can do anything with that direction
float v = Input.GetAxis("Vertical");
float speed = 10f;
sourceTransform.position += direction * (v * speed * Time.deltaTime);
``````

@BenZed Thanks for the response, I’m trying to make it work now, as it gives me an error: Unexpected symbol ‘’

Edit:
I got it to work but the movement is reversed xD but I’ll take care of it hopefully. Thank you a lot, sir!

Edit2: OK, it works fine when I move forward, but I can’t turn using keyboard now.