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 /
  • Help Room /
avatar image
0
Question by pshekhter · Mar 08, 2016 at 12:46 AM · camerascripting problemmovement scriptshootertop-down

Movement Flipped in Game View?

I am making a 3D, top-down shooter, and have run into a bit of an issue with my camera. The camera is above the player, pointed straight down, and is Orthographic, Size 20, with default clipping planes and Viewport Rect. It has a script attached:

 using UnityEngine;
 
 public class CameraFollow : MonoBehaviour
 {
     public double height = 20.0;
     public double distance = 15.0;
     public double maxSeparation = 60.0;
     public float speed = 0.5f;
     public Transform trgt;
 
     void Awake()
     {
         transform.position = trgt.position;
         transform.position += new Vector3(0, -(float)distance, (float)height);
         transform.LookAt(trgt);
     }
 
     void Update()
     {
         Renderer renderer = trgt.GetComponent<Renderer>();
         if ((Vector3.Distance(transform.position, trgt.position) >= maxSeparation) || !(renderer.isVisible) || (Vector3.Distance(transform.position, trgt.position) == 0))
         {
             transform.position = Vector3.Lerp(transform.position, trgt.position, speed);
             transform.position += new Vector3(0, -(float)distance, (float)height);
             transform.LookAt(trgt);            
         }
     }
 }

Currently, the variables are set to:

 Height = 20
 Distance = 0
 Max Separation = 27
 Speed = 1
 Trgt = Player (Transform)

Movement is handled in a separate script, which uses AddRelativeForce and AddTorque.

This first is inside the script's FixedUpdate() function (only relevant code):

         // If player can't move or game is paused
         if (!playerCanMove || Time.timeScale == 0f)
         {
             return;
         }
 
         // Get input axis and process input
         MovePlayer();
 
         Vector3 movement = new Vector3(hAxis, 0.0f, vAxis);
 
         if (movement.magnitude < _deadZone)
         {
             // Debug.Log("No movement");
             movement = Vector3.zero;
         }
         else
         {
             // Debug.Log("Moving...");
             movement = movement.normalized * ((movement.magnitude - _deadZone) / (1 - _deadZone));
         }
 
         if (movement != Vector3.zero)
         {
             var accelMultiplier = 1 - (_rigidbody.velocity.magnitude / _topSpeed);
             // Debug.Log("accelMultiplier: " + accelMultiplier);
             _rigidbody.AddRelativeForce(movement * _thrust * accelMultiplier * Time.deltaTime, ForceMode.VelocityChange);
         }
 
         if (rotateDir != 0.0f)
         {
             var turnMultiplier = 1 - (_rigidbody.angularVelocity.magnitude / _topAngVelocity);
             _rigidbody.AddTorque(transform.up * rotateDir * _turnSpeed * turnMultiplier * Time.deltaTime, ForceMode.VelocityChange);
         }

And here's and the MovePlayer() function:

     private void MovePlayer()
     {
 
         hAxis = CrossPlatformInputManager.GetAxis("Horizontal");
         vAxis = CrossPlatformInputManager.GetAxis("Vertical");
         float r = CrossPlatformInputManager.GetAxis("Rotate");
 
         if (Mathf.Abs(r) > _deadZone)
             rotateDir = r * ((r - _deadZone) / (1 - _deadZone));
 
         if ((r < 0) && (rotateDir > 0)) rotateDir = rotateDir * -1;
     }

All variables are properly initialized in the Awake() function. Despite this, my horizontal input is shown to be reversed - pressing the right button appears to move the character left, and left right. This even happens with the XBOX 360 controller, so it's not that the axes are flipped. Further, this is only how it appears in the camera - the Scene View shows the character moving as expected.

Note that movement occurs along the X-Z plane only.

I suspect it's a bug in the CameraFollow class, but I'm not sure.

Thank you for any help you can give me with this problem. It's probably something easy I've overlooked, but I'm pretty new at this.

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

63 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me with this camera orbiting script? 0 Answers

How to script a random asset generator> 0 Answers

How can I get all cameras enabled true false states ? 0 Answers

Boolean variable is never true, even if declared true or ticked in the inspector 1 Answer

Sprite mouse movement Unity2D 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