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 sruthidivakar · May 30, 2014 at 09:45 AM · cameramouselookshooter

3rd pserson shooter camera issue

I am developing a third person shooter game for mobiles. Here I am using the following script to control the camera movement.

using UnityEngine; using System.Collections;

public class mouse_controller : MonoBehaviour {

 [AddComponentMenu("Camera/Simple Smooth Mouse Look ")]

 Vector2 _mouseAbsolute;
 
 Vector2 _smoothMouse;
 
 public Vector2 clampInDegrees = new Vector2(80, 20);
 
 public bool lockCursor;
 
 public Vector2 sensitivity = new Vector2(0.9, 0.9);
 
 public Vector2 smoothing = new Vector2(2, 2);
 
 public Vector2 targetDirection;
 
 public Transform target;

 public float range = 1000;
 public float force = 1000;

 // Use this for initialization
 void Start () 
 {
     targetDirection = transform.localRotation.eulerAngles;
 }
 
 // Update is called once per frame
 void Update () 
 {
     transform.position = new Vector3 (target.position.x,target.position.y,target.position.z);


     
         if(Input.mousePosition.x > Screen.width/1.5f && Input.mousePosition.y < Screen.height/3)
         {
             
         }
         else
         {
             if (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Moved) 
             {
                 Screen.lockCursor = lockCursor;
                 var targetOrientation = Quaternion.Euler(targetDirection);
                 
                 var mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
                 mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity.x * smoothing.x, sensitivity.y * smoothing.y));
                 
                 _smoothMouse.x = Mathf.Lerp(_smoothMouse.x, mouseDelta.x, 1f / smoothing.x);
                 _smoothMouse.y = Mathf.Lerp(_smoothMouse.y, mouseDelta.y, 1f / smoothing.y);
                 _mouseAbsolute += _smoothMouse;
                 
                 //--- Horizontal Movement ---
                 if (clampInDegrees.x < 85)
                 {
                     _mouseAbsolute.x = Mathf.Clamp(_mouseAbsolute.x, -clampInDegrees.x * 0.5f, clampInDegrees.x * 0.5f);
                 }

                 var xRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.right);
                 transform.localRotation = xRotation;
                 
                 //--- Vertical movement ---
                 if (clampInDegrees.y < 25)
                 {
                     _mouseAbsolute.y = Mathf.Clamp(_mouseAbsolute.y, -clampInDegrees.y * 0.5f, clampInDegrees.y * 0.5f);
                 }
                 transform.localRotation *= targetOrientation;
                 
                 var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, transform.InverseTransformDirection(Vector3.up));
                 transform.localRotation *= yRotation;
             }
         }
 }

}

When i drag on the screen camera smoothly rotate. But the issue is when click after the fire button(for shoot)with right hand,same time user also has the provision to change the camera position with his left hand. After pressing the fire button camera suddenly switch to the left touched position without considering the Lerp values. This will happen rarely. please help me to findout the issue

I expect an output like Frontline Commando2

Thanks in advance..

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 meat5000 ♦ · May 31, 2014 at 02:00 AM 0
Share

At a glance I'm guessing you need to take another look at how Lerp works.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by gamertest · Jun 20, 2014 at 10:34 AM

Have 1 mouse look script attached to the overall parent of your character, and make the mouse-look script only active on the x-axis. then on the head of your character, add the mouse-look script only active on the y-axis. now that's your 3rd person view. attach another camera to your head and set is to only move on the x-axis, and disable it when you turn mouse look mode to off, disable the mouse-look script on the overall parent and enable the x-axis mouse-look script on the head of your character.

Comment
Add comment · Show 1 · 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 meat5000 ♦ · Jun 20, 2014 at 10:36 AM 0
Share

Please stop guerrilla-posting spam links. Edited out.

Last chance.

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

22 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

Related Questions

MouseLook movement diagonal stutters... 0 Answers

MouseLook.cs:case of JavaScript 1 Answer

How to lock camera roll in C# 1 Answer

How do I disable mouse to turning right 0 Answers

Controlling MouseLook script with keys/joystick 1 Answer


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