King09
December 31, 2017, 10:36pm
1
I cannot move my character when i rotate it using the mouse when it rotates the character freezes, and i cannot move forward nor backwards. NEED HELP been trying to figure this out all day.
void Update()
{
float rX = Input.GetAxis(“Mouse X”) * smooth;
rY += Input.GetAxis(“Mouse Y”) * smooth;
rY = Mathf.Clamp(rY, -45, 45);
transform.Rotate(0, rX, 0, Space.World);
if (cam != null){
Vector3 rot = new Vector3(-rY, cam.transform.eulerAngles.y, cam.transform.eulerAngles.z);
cam.transform.eulerAngles = rot;
}
}
void FixedUpdate () {
if (Input.GetKey(KeyCode.W))
{
rb.MovePosition(transform.position + transform.forward * movespeed);
anim.SetBool(“walking”, true);
}
if (Input.GetKey(KeyCode.S))
{
rb.MovePosition(transform.position + transform.forward * -movespeed);
anim.SetBool(“walking”, true);
}
}
I tested it on a cube and it rotates and moves at the same time. I didn’t have an animator on it, so I commented out those lines. There really isn’t a reason for it to interfere that I can see.
Hi there. Have you been able to work this out, yet?
Please look over this page for how to post code nicely on the forums for future posts
If you see someone who needs to know about code tags, please link them to this post:
Please use code tags when posting code.
You can "tag" your code by typing [984347--130826--Screenshot 2015-03-16 10.33.58.png] around your code.
There is no overt "Code" tag button that automatically tags a selection as code.
That being said, however, we can Insert code directly into the post using the "Insert Code" button:
[image]
This will bring up an "Insert" window were we can paste our code and c…