Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by ke1th · Jul 31, 2015 at 12:10 PM · rotationmovementfpsmouselook

Issues with camera and player rotation scripts for basic FPS controller.

Hello! I'm new to Unity and game development in general. As of now, I'm trying to make a simple 3rd person shooter game. I'm starting off by creating a simple scene for testing, adding a player, giving it movements and adding a camera.

I find movement and camera very important which is why I refrain from using advanced prefab or over developed scripts, as they often come with additional functions that I don't want or need. Currently, I'm using these scripts for my player game object:

  • Movement - http://pastebin.com/rfGTV6iT (http://docs.unity3d.com/ScriptReference/CharacterController.Move.html)

  • MouseLook - http://pastebin.com/vW15FcpL (SimpleMouseRotator.cs accessible in the standard assets->utility scripts)

So, here are my current issues:

  • Issue with movement script: pushing keys that would move the player in the opposite direction doesn't cancel movement (eg. pushing and holding down W and then S doesn't stop the player from moving forward). I would like the player to stop walking, and upon releasing W with S still held down, move backwards.

  • Also I would like it to be possible to move the player slightly while in the air. Sort of like air acceleration. What is a good way of doing so? Adding a rigidbody-component and adding force to a player whilst isGrounded = false?

  • With the current MouseLook-script, the player model rotates horizontally which is all good. When aiming higher or lower however, the player model starts flipping around like crazy. I would like the player model to remain in an upright position but for the camera (and hypothetical crosshair/target) to follow the mouse movements. Any help is appreciated!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ke1th · Jul 31, 2015 at 02:54 PM

I found a solution for the third issue (the one where MouseLook rotation of player caused the player to fall). This was to give player the MouseLook to work horizontally and the camera to only work vertically. No idea if this is appropriate or if it will cause problems further in. :d

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
0

Answer by mihai_pruna · Apr 17, 2016 at 12:10 PM

This is for Unity 5.3 Here's a simple script to get a first person controller mouse look to work sort of OK, like in a FPS game. I used this with a rigid body FPS controller script attached to the camera.

In mouseLook.cs, change the beginning of the LookRotation function, up to and including the line where it sets the m_CameraTargetRot:

     public void LookRotation(Transform character, Transform camera)
     {
         float yRot = CrossPlatformInputManager.GetAxis("Mouse X") * XSensitivity;
         float xRot = CrossPlatformInputManager.GetAxis("Mouse Y") * YSensitivity;

         //camera rotates on its own local axes
         //get the camera forward direction in relation to the world
         Vector3 fwd = camera.forward;
         fwd.Normalize (); 
         //rotating around the y and z local axes depends on camera forward direction
         float newyrot = yRot *(float) Math.Sqrt (fwd.x * fwd.x + fwd.z * fwd.z);
         m_CameraTargetRot *= Quaternion.Euler (-xRot, newyrot, yRot*fwd.y);
     
 
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Noob: Question about standard c# mouselook script. And other probably noob questions others may ask. 3 Answers

Player not rotating with camera 1 Answer

Multiplayer Mouselook on Soldier (FPS) 0 Answers

click to move workig script!! but pls help with rotation!! :( 1 Answer

How to make a RigidBody not go into ground when tilted foward? 2 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