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 khoatic · Jan 04, 2014 at 07:55 AM · transformrotate objectmove an objectrelative rotation

Object rotating around object at two levels

So im trying to have a spotlight move around the player in a fixed manner with a 3rd person perspective. The Spotlight moves to follow where the mouse is relative to its fixed rotation point around the player. On top of it the spot light is constantly pointing outwards and should never face the player. Lastly Im hoping to be able to make the spotlight look up or down if necessary, also be able to move the spotlight up or down if possible. I have simple version that does everything but the adjustments to the look direction and the start height of the spotlight, so i think im doing something wrong. Any help is greatly appreciated, Thanks in advance.

 public void lightMouseMovement()
     {
         float distToLight;
         float distToLookAt;
         Plane playerPlane;
        float rayDist = 0f;
  
  
        //Distance from Player to Light Object
         distToLight = (player.transform.position - this.transform.position).magnitude;
         //Distance from Player to Light Look At Object
         distToLookAt = (player.transform.position - lookAtObject.transform.position).magnitude;
         playerPlane = new Plane(Vector3.up, player.transform.position);
  
        //Creates ray from Screen to Point
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  
        //Sets rayDist to distance from Camera to movementPlane OR cancels out(parallel or opposite direction)
  
  
         if (playerPlane.Raycast(ray, out rayDist)) 
        {
          //Get Collision Point in world space
          Vector3 point = ray.GetPoint(rayDist);
          //Move to new Rotational Posistion
             this.transform.position = player.transform.position + (point - player.transform.position).normalized * distToLight;
  
        }
         if (playerPlane.Raycast(ray, out rayDist))
         {
             //Get Collision Point in world space
             Vector3 point = ray.GetPoint(rayDist);
             //Move to new Rotational Posistion
             lookAtObject.transform.position = player.transform.position + (point - player.transform.position).normalized * distToLookAt;
  
  
         }
         //Make Height Adjustment to new point
         this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + lightYAdj, this.transform.position.z);
         lookAtObject.transform.position = new Vector3(lookAtObject.transform.position.x, lookAtObject.transform.position.y + lookAtYAdj, lookAtObject.transform.position.z);
        //Turn Light to Look at Look At Object
        this.transform.LookAt (lookAtObject.transform.position);
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

Answer by pointcache · Jan 04, 2014 at 07:58 AM

Maybe raycast on screen, take hit point, subtract vectors, apply to pointlight.

Comment
Add comment · Show 5 · 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 khoatic · Jan 04, 2014 at 08:08 AM 0
Share

right now I Im shooting a ray onto a premade Plane, getting the point from that, subtracting that hit point from the players position then adding it to the current players position to get its new location. To make sure its fixed im normalizing the (hit-Player) and multiplying it by the distance between the (player-light) position.

avatar image khoatic · Jan 04, 2014 at 08:11 AM 0
Share

The main problem is making the spotlight look up or down on this track, or even raising the track. I could rotate where its looking but as it rotates it wouldnt rotate around as well, so it would hit the player. I have it now so im rotating two objects, one the spotlight the other a lookat point so it can rotate around while looking outwards.

avatar image pointcache · Jan 04, 2014 at 08:21 AM 0
Share

Try to make a "rig" a set up of parented objects where each in hierarchy is affected differently providing the final motion you need, that's what i did with complex camera setups and many other things.

avatar image robertbu · Jan 04, 2014 at 08:24 AM 0
Share

You should be able to solve this problem simpler than using a second, look-at object. Posting your code would help the folks in the list give you an accurate answer.

avatar image khoatic · Jan 04, 2014 at 08:18 PM 0
Share

I just updated the post to include my current code. I originally thought that as well but I was having no luck on getting this result.

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

19 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

Related Questions

How do I set and get local rotation of objects 1 Answer

Two problems One code 1 Answer

Object Rotating around center from Mouse Movement 1 Answer

Rotating an already rotated object. 1 Answer

How to move child objects perpendicular to parent object's rotation? 2 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