Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Rorin · Jan 20, 2014 at 09:13 PM · rotationplayergun

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges