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 /
avatar image
0
Question by xXx12aithexXx · Aug 25, 2017 at 01:35 AM · mousepositionmouselookscreentoworldpointaimingworldtoscreenpoint

Move Object - Mouse Input Y Axis from Camera

Hi, i'm working on a tps game ... right now i'm working on the hip fire aiming mecanism that uses mecanim offcourse for animation process...

However i'm riddling my self with a simple problem.... I do not want to use the camera to create a 3d target from camera to world space not what i'm trying to achieve ...

To make things simple I have a cross hair object that is parented to the main player object that controlls the player's movement based on mouse input * damping and sensitivity values...

So the idea is to have this 3D cross hair fallow the visual 2D one that uses a mouse controller input script...

Here is the crossHair script...

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CrossHair : MonoBehaviour {
 
     [SerializeField]Texture2D image; 
     [SerializeField]int size;
     [SerializeField]float maxAngle;
     [SerializeField]float minAngle;
     [SerializeField]float targetDistance;
     public float lookHeight;
 
     public Transform cross_target;
 
 
     public void LookHeight(float value)
     {
         lookHeight += value;
 
         if (lookHeight > maxAngle || lookHeight < minAngle)
             lookHeight += value;
     }
 
 
     void LateUpdate()
     {
         //this is where the cross_target Transform code should go
 //this is only move along the y position then rotates with player movement
 
     
     }
 
 
 
 
 
     void OnGUI()
     {
         Vector3 screenPosition = Camera.main.WorldToScreenPoint (transform.position);
         screenPosition.y = Screen.height - screenPosition.y;
 
 
         GUI.DrawTexture(new Rect(screenPosition.x, screenPosition.y - lookHeight, size, size), image);
             
 
             
     }
 
 }
 


and to give you a idea as to some placement where the actual mouse input is modified.... is here...

 void LookAround ()
     {
         mouseInput.x = Mathf.Lerp (mouseInput.x, playerInput.MouseInput.x, 1f / MouseControl.Damping.x);
         mouseInput.y = Mathf.Lerp (mouseInput.y, playerInput.MouseInput.y, 1f / MouseControl.Damping.y);
 
         transform.Rotate (Vector3.up * mouseInput.x * MouseControl.Sensitivity.x);
 
         CrossHair.LookHeight (mouseInput.y * MouseControl.Sensitivity.y);
         //playerAim.SetRotation (mouseInput.y * MouseControl.Sensitivity.y);
     }

So ideally the new 3D transform should just move along the with the look height parameter of the CrossHair script however i'm having major problems I've tried taking the screenPosition Vector3 values then declaring a new vector 3 that converts it back to world space and use only that newly vector3 y value....

I highly appreciate the feedback in advanced , Thank you

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 xXx12aithexXx · Aug 25, 2017 at 01:36 AM 0
Share

So basically move the 3d cursor with the 2D one sorry.

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

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

Related Questions

Having player object always snap to mouse position 1 Answer

Top Down shooter mouse controls 2 Answers

camera.main update problems with screenToWorldPoint 1 Answer

Camera.ScreenToWorldPoint with Perspective camera 1 Answer

Use input.mouseposition to rotate camera 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