Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Dec 22, 2016 at 11:44 AM by Droki for the following reason:

Solved

avatar image
0
Question by Droki · Dec 20, 2016 at 03:24 PM · rotationscripting problemmovement script

How do I add camera rotation while moving a player sideways?

After experimenting for a couple of days I still haven't found a decent manner to rotate a player cam horizontally with the A and D keys (assuming classical mapping). I am aiming for something like the first DOOM's movement. How do I achieve this?

 using UnityEngine;
 
 using System.Collections;
 
 public class MoveyCube : MonoBehaviour 
 
         public float maxSpeed = 6f;           
         public float maxAcelleration = 100;    
         Vector3 movement;                  
         public float acelleration = 0f;        
         Rigidbody playerRigidbody;      
         Vector3 rotatevector;
         int rotspeed;
                   
 
 
         void Awake ()
         {
             playerRigidbody = GetComponent <Rigidbody> ();
         }
 
 
         void FixedUpdate ()
         {
             float h = Input.GetAxisRaw ("Horizontal");
             float v = Input.GetAxisRaw ("Vertical");
 
 
             Move (h, v);
 
             if (acelleration < maxSpeed && Input.GetKey (KeyCode.W) || Input.GetKey (KeyCode.S) || Input.GetKey (KeyCode.A) || Input.GetKey (KeyCode.D)) 
             {
                 acelleration += 1;
                 if (acelleration >= maxSpeed)
                 {
                     acelleration = maxAcelleration;
                 }
             } 
             else 
             {
                 acelleration -= 1;
                 if (acelleration <= 0)
                 {
                     acelleration = 0;
                 }
             }
         }
 
         void Move (float h, float v)
         {
             movement.Set (h, 0f, v);
             movement = Camera.main.transform.TransformDirection(movement);
             movement = movement.normalized * acelleration * Time.deltaTime; // Anti diagonal extra speed measure
             
             playerRigidbody.MovePosition (transform.position + movement);
             rotatevector.Set (0, h, 0);
             Camera.main.transform.Rotate(rotatevector * Time.deltaTime);
 
         }
         
     }

Comment
Add comment · Show 1
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
avatar image Glurth · Dec 20, 2016 at 04:45 PM 1
Share

Do you mean, look sideways while running forwards? Sorry, been few years since I played DOO$$anonymous$$ ;) Does A & D control "look", not "strafe", and not "Turn"?

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Droki · Dec 22, 2016 at 11:45 AM

Solved it by messing with standard vectors in transform.rotate. Thanks for the answers though!

Comment
Add comment · Share
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
avatar image
1

Answer by Thomas-Hawk · Dec 20, 2016 at 05:01 PM

You want the mouse to control the player's rotation left and right, and have the camera follow the player and its rotation (pretty much, unless you want smoothing which you don't, just set the camera as a child of the player). A and D would translate/straffe the character, not rotate the camera, in classic DOOM.

Maybe you're thinking of "Tank Controls"

Comment
Add comment · Share
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

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Unity 2D movement and rotate sprite to the direction it is moving in 1 Answer

My gameobject only moves to the right once and then stops, why? 3 Answers

orienting player in one direction 1 Answer

[ C#] Character Movement based on Camera Direction. 2 Answers

Temporary GameObject Movement 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