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 whalesnail · Oct 14, 2012 at 01:33 AM · mouselasertowards

shooting laser towards mouse

I'm trying to make a 2D game with a laser that the player can shoot that reflects off of mirrors, but I'm kinda new to Unity.

It all works, except that I can't get the player to fire the laser at the mouse position. I have no trouble getting the mouse position using:

 Vector3 screenPos = Input.mousePosition;
 screenPos.z = 0;
 Vector3 worldPos = Camera.mainCamera.ScreenToWorldPoint(screenPos);


But simply using the LookAt() function like all the tutorials show will not work for me. Because of the equation I'm using to calculate reflection, I need a single value out of 360 to define the direction the laser is moving in. I'm going with the EulerAngle.z value. So basically, what I need is to get the direction from the player's x and y position to the mouse position in a single value out of 360. Then I can just set the laser's eulerAngles.z rotation to that.

Any help of any kind would be appreciated, especially in C# as that is the language I'm using.

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

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MountDoomTeam · Oct 14, 2012 at 06:57 AM

try just getting your program to print the start pt, end pt and the vector line of both of the points.

it's a FPS view? Ok, your explanation was making sense, and then the question became analytically incoherent and confused, like you dont know the 3d x y z stuff.

if you need a single value out of 360, you need an int. if you need a single value out of 3d eulerAngles x.y.z then you need just a value on the z azis, like a point in space with y z = 0.

cos you talk of geometry you have to be clear on points, lines, surfaces, like planes, .

you need the player point, here u are using the camera so FPS. then you need the point you aim at. it is another XYZ point in 3d.

Then you have to get the 2 points and make a line coordinate,

search answers and reference for "make a line from 2 points" it's a kind of vector3 in unity , for lines and points. it's called a vector, and it can can have direction info or no, like going from A to B or B to A. also learn to do this:

to be honest you arent thinking about the program clearly, it's geometry, you need point a and b, their line, the angle of the mirror, the difference between the euler of the mirror and the lazer, and do the maths on that. that's what you are asking us. the points a and b are x y z, the vector is x y z is a vector, and the rotations are also xyz. print all their values and understand the graph data in x y z.

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

11 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

Related Questions

How to make an object rotate on the y axis towards the mouse? 3 Answers

Smoothing out rotations 1 Answer

Move the player(cube) to the enemy(cube) by clicking on enemy? 1 Answer

Object reference not set to an instance of an object 0 Answers

Move the player towards the cube to attack. 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