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
1
Question by sirbranedamuj · Apr 07, 2013 at 03:14 PM · raycasttransformrotatespotlightcone

Set forward vector of an object to be EXACTLY equal to another vector.

I have been racking my brain over this for a couple hours now but I can't figure this out.

I have a spotlight object. This spotlight has a special shader and texture on it to give it the spotlight cone effect. It's not an actual spotlight, it's just a cone mesh with a texture.

Every frame, a raycast is fired from the player's mouse position. The spotlight must rotate such that it satisfies the following conditions:

  1. The center of the cone passes through the RaycastHit.point Vector3

  2. The tip of the cone remains in its initial location (the lamp object which is emitting this "light")

I've got it working with arrow keys:

 transform.RotateAround(rotateAround.position, Vector3.right, vertical);
 transform.RotateAround(rotateAround.position, Vector3.up, horizontal);

I use a Transform called "rotateAround" which serves as the "anchor" point, so to speak, for the spotlight. It rotates around this point based on the vertical and horizontal input axes. It rotates around the right axis to move it up and down, and it rotates around the up axis to move it left and right.

But now I need to make this work with a point in space. I want to rotate the cone such that the line that passes through the tip and the center of the base also passes through the raycast hit point while also keeping the tip stationary.

Comment
Add comment · Show 2
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 Fattie · Apr 07, 2013 at 08:16 PM 0
Share

"the line that passes through the tip and the center of the base also passes through the raycast hit point while also keeping the tip stationary"

HUH ??

You'd have to add a diagram champ. That's the most confusing thing I've ever heard and I used to read books on topology. Plus it's totally different from the title.

it's very likely you just add a wrapper object with the center at "some point" and then move the wrapper object to, uh, the other point

avatar image Loius · Apr 07, 2013 at 08:42 PM 0
Share

Use shenanigans to make your pivot point an object. Either create a new object and child the cone to it, or fix the cone's mesh so its pivot is at its tip. Save yourself eight million headaches, trust me.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by whydoidoit · Apr 07, 2013 at 04:42 PM

You can set the forward vector using

      transform.forward = theVectorYouWant;

Or by using:

      transform.rotation = Quaternion.LookRotation(theVectorYouWant);
Comment
Add comment · Show 3 · 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 sirbranedamuj · Apr 07, 2013 at 04:50 PM 0
Share

This doesn't solve the problem of keeping the tip of the cone stationary.

avatar image whydoidoit · Apr 07, 2013 at 05:01 PM 1
Share

Why are you moving it then? I must have missed something.

avatar image whydoidoit · Apr 07, 2013 at 05:01 PM 0
Share

It should do if the tip of the cone is at local 0,0,0

avatar image
1

Answer by MikeNewall · Apr 07, 2013 at 03:49 PM

I think if you had a parent gameobject which shares the same position as the point of your cone it should work. You can use the parent gameobjects transform in place of "rotateAround". It's just a case of having the pivot point in the place you want to rotate around.

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

14 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

Related Questions

Raycast Rotate Help 1 Answer

transform.Rotate(Vector3.up ... not working 0 Answers

Plane Control Script rotating unexpectedly 1 Answer

Rotate Around Object 2 Answers

How to raycast always in direction of a object? 3 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