- Home /
Character Rotation Doesn't work
Hello guys It's me again. This time I've started my newest learning project but I'm having a very big issue with the moving script of the player. Here is the deal:
-When I press WASD to move my char moves with this script: using UnityEngine; using System.Collections;
public class Movement : MonoBehaviour {
bool facingRight;
public float speed;
private Quaternion rotation;
void Start ()
{
renderer.material.color = Color.magenta;
}
void Update ()
{
//transform.eulerAngles = new Vector3(transform.eulerAngles.x,0,transform.eulerAngles.z);
if (Input.GetKey (KeyCode.UpArrow)) {
transform.Translate(Vector3.forward*(speed*Time.deltaTime));
}
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.Translate (Vector3.left * (speed * Time.deltaTime));
}
if (Input.GetKey (KeyCode.DownArrow)) {
transform.Translate(Vector3.back*(speed*Time.deltaTime));
}
if (Input.GetKey (KeyCode.RightArrow)) {
transform.Translate(Vector3.right*(speed*Time.deltaTime));
}
}
}
And it moves perfectly fine but then I come across the problem with the barrel attached infront of the object [ cube (player) ] from which I fire my bullets, the character [ cube ] doesn't rotate. So I can't fire my bullets on sides just infront of me. I've tried several scripts but they all fail in some way. I want to be able to shoot and move to the right [ 90 degrees ] then to the left [ -90 or 270 degrees ] and then to the bottom [ 180 degrees i think ] I can't seem to do so........... I need a script to be able to move to all sides even when I press A and W to move up and left, W and D to move up and right, S and D to move down and right and S and A to move down and left.
How can I do this? And please write me a sample code because many people told me some theories but I can't seem to implement them in the right way. I'm very new to unity and a bit to programming in unity, go easy on me :)
Thank you !!! I'll really appreciate it if someone helps me ! I want this script to do so because I want the game to be for 2 players and both have controls on 1 keyboard, one moves with WASD and the other with Arrow Keys.
Have a nice day/evening :)
Your answer
Follow this Question
Related Questions
How to add gun to the model, as when it animate, the gun is dis-positioned. 2 Answers
How to make a player rotate in a direction with a slope of the ground. 0 Answers
Rotating the player animation also rotates the player 2 Answers
Make player face different enemies with the same tag 0 Answers
Rotate to face player, drunk issues 0 Answers