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 Sangar · Mar 23, 2014 at 05:15 PM · charactertargetturretpivotpivot-point

How to make a turret focus on a point?

Hi there,

I have followed a tutorial online to have a turret following my characters position and shooting in that direct, however fro some reason my stock characters "focal" point is pretty misaligned? I have tried using the character head as a target for the turret, however it refuses to even move in that case. I have tried adding an empty gameObject as a child of my character and using that as the target but again no luck with the turret giving any reaction. You can see from my screenshot below how the turret works: ![Facing into the ground][1] (as a side note, my player is also slanted for some reason?

Here is the code I am using for the turret movement:

 var target : Transform;
 var turret : Transform;
 var damp = 1.0;
 var bullet : Transform;
 var bulletSpawn : Transform;
 var timer = 0.0;
 
 
 function OnTriggerStay (other : Collider)
 {
 timer+= Time.deltaTime;
     if (other.transform == target)
     {
         turret.transform.LookAt(target);
         if (timer>0.5)
         {
         Instantiate(bullet, bulletSpawn.position, bulletSpawn.rotation);
         timer = 0.0;
     }
     }
 }

Many thanks! [1]: /storage/temp/24121-screen+shot+2014-03-23+at+16.47.10.png

screen shot 2014-03-23 at 16.47.10.png (147.6 kB)
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 SkaredCreations · Mar 23, 2014 at 06:11 PM

Your turret source model is probably not aligned with Unity directions (that are Y-up, Z-forward), set the rotation of your turret to 0,0,0 in the scene editor and see if it's facing forward (Z-positive direction) correctly: if it's not then you can just parent the turret to a gameobject with rotation 0,0,0 and align the turret transform rotation to face forward (or fix the rotation of the source model in your 3D software). About your player rotation you're most likely rotating it in X/Z instead of only Y in your scripts.

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

21 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

Related Questions

Make the turret automatically rotate to look at where the crosshair is aimed at. 3 Answers

Devil May Cry style Lock-on Movement? 2 Answers

Freeze object rotation on Polybrush 1 Answer

How to make an object to look at Raycast Hit Point? 1 Answer

Turrets |Aiming don't work 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