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 /
This question was closed Jun 28, 2020 at 06:07 AM by nikhilVardhan for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by nikhilVardhan · Jun 28, 2020 at 05:05 AM · linerendererorthographic cameraperspective camera

Why Line Renderer always move towards the same spot in perspective projection but not in orthographic projection.

When i am using perspective position of camera then no matter where i click on the screen, the ray is always goes towards a fixed point, which is (0,0,0) i think. But it is not the matter with orthographic projection. It works fine, the rays always move towards the projected position(using mouse click) in orthographic projection.

This is my script:

public class onClickShoot : MonoBehaviour { LineRenderer line; public Transform initialState; Vector3 targetState; private WaitForSeconds shotDuration = new WaitForSeconds(.5f);

 void Start()
 {
     line = GetComponent<LineRenderer>();
 }

 void Update()
 {
     
     line.SetPosition(0, initialState.position);

     if (Input.GetMouseButtonDown(0))
     {
         getTarget();
         StartCoroutine(shooting());
         
     }
     
 }

 void getTarget() {
     targetState = Camera.main.ScreenToWorldPoint(Input.mousePosition);
     targetState.z = 10;
     line.SetPosition(1, targetState);
 }

 private IEnumerator shooting()
 {
     line.enabled = true;
     yield return shotDuration;
     line.enabled = false;
 }

}

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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by nikhilVardhan · Jun 28, 2020 at 06:06 AM

I used this script to solve the error.

Script:

public class getObjectPosition : MonoBehaviour { LineRenderer line; private void Start() { line = GetComponent(); } private void Update() { line.SetPosition(0, transform.position); if (Input.GetMouseButtonDown(0)) { float rayLength = 100.0f; // This is the length of the ray. You need to figure out how long it must be in order to hit all of the cubes in the scene. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit;

         if (Physics.Raycast(ray, out hit, rayLength))
         {
             if (hit.collider != null)
             {
                 Debug.Log(hit.collider.transform.position);
                 line.SetPosition(1,hit.collider.transform.position);
             }
         }
     }
 }

}

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

128 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 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

Objects overlapping in perspective rather than real space? 1 Answer

Camera zoom AND smooth transition? 0 Answers

How to match 3dsmax camera perspective with unity 0 Answers

Problem with depth clipping and perspective camera 1 Answer

Lens Flares Arent visible in Orthographic 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