• 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 T27M · Mar 21, 2012 at 08:00 PM · rotationgameoffset

Rotation Offset

Hi

I have a simple game im playing around with. What I currently have is a fps controller which I have removed everything but the "mouse look" script, the main camera(player) is looking down a shooting range, on each side of that I am going to have a turret also point down the range.

What I want the turret(s) todo is to point relative to where the player is looking(FIG 1), I can make the turrets inherit the camera rotation but when I try to ajust that rotation based on the angle from the main camera i cant seem to get it to work. The turret just flips around on its axis and sticks no longer follwing any input(FIG 2).

Thanks

alt text

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

3 Replies

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

Answer by Kroltan · Mar 24, 2012 at 09:43 PM

Try making a raycast out of your player's view, then use LookAt in the turrets with the coordinates of the raycast hit point.

Comment
Add comment · Show 2 · 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 T27M · Mar 25, 2012 at 01:04 PM 0
Share

Thanks man that worked =)

avatar image T27M · Mar 25, 2012 at 01:16 PM 0
Share

Is there a way to make the turret look at a little smoother? For example if I have something in the foreground and look at something far away it will instantly snap to that point.

I was going to make turret rotation speed upgradeable

Cheers

avatar image
0

Answer by T27M · Mar 25, 2012 at 02:38 PM

var target : GameObject;

function Update () {

 var fwd = transform.TransformDirection(Vector3.forward);

 var hit : RaycastHit;

 Debug.DrawRay(transform.position, fwd * 50, Color.green);



 if(Physics.Raycast(transform.position, fwd, hit, 50)){

     target.transform.LookAt(hit.point);

     Debug.Log(hit.point);

 }

}

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

Answer by DaveA · Mar 21, 2012 at 10:58 PM

Do you want the turrets to LookAt the target? Or look in the same direction as the camera. Fig 2 is the latter, they all look down the range, straight down. If you want the turrets to look at the target, use transform.LookAt(target). If you want them to look a some point down range, you need to know how far down range that is.

Comment
Add comment · Show 2 · 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 T27M · Mar 22, 2012 at 07:51 PM 0
Share

I want them to point where the player looks. So if the player looks at a target the turrets need to rotate to point at that target. Since they are not at the position of the player, they are either side of the player, they need to correct their own rotation based on the distance from the player, but I'm not sure on the best way to code this.

Fig 2 is showing how I have it currently, its basicly just inheriting the rotaion of the camera(player). But I don't want it this way because the turrets will never actualy shoot where I am ai$$anonymous$$g. I tried to add an offset but I just got some strange results.

Also the rotation of the turret model is different from the world rotation and that was causing me some headaches aswel. I put the object in an empty and the script onto that which seemed to fix it, but I still can not get it to rotate to where the player looks.

avatar image T27M · Mar 24, 2012 at 08:31 PM 0
Share

=/ still stuck any ideas ?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Mimic other object's rotation on one axis (with offset) 0 Answers

Need Help with random rotatition on game turret 2 Answers

Limit Rotation of Camera around a player using keyboard 1 Answer

Handle screen rotation manually 0 Answers

Enemy Rotation Problem 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