Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Character Rotation Doesn't work

$
0
0
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 :)

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>