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 boddole · Mar 07, 2015 at 02:10 PM · c#rotationlerprotate objectrotatetowards

Question on Forcing a Specific Rotation

Hello everyone, I'm looking to create a specific type of rotation, and I'm not quite sure how to describe it, so I hope the picture makes it clear (and if there is a term for this, please let me know). I suppose I could create another point and first make my gun rotate towards that, but if at all possible, I'd like to accomplish this without "sub-rotations" and extra GameObjects.

As in the picture, I am trying to guarantee that the "gun object" will only rotate along that specific arc (and not try to go through the wall because the angle is less/distance is shorter). Ideally, I would like to use RotateTowards() since it is guaranteed not to overshoot the target, but if that won't work in this case that's fine (I'll try to convert a "rotation speed" into a equivalent lerp speed).

UPDATE:

Based on responses, I've added some clarification as to how the gun is working:

The gun starts in the "Center Position". When a target is discovered, the gun rotates to face the port that found the target(constrained by the "arc" so that it will stay in the turret housing). Then the gun moves forward to that gun port. When the target is gone or "overridden" by the player, the gun moves back to center, waiting until one of the gun ports finds a new target / or rotates and then moves to the new "active" gun port.

alt text

turret-rotation-example.jpg (132.6 kB)
Comment
Add comment · Show 5
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 Glurth · Mar 07, 2015 at 03:06 PM 0
Share

I'm not quite clear on this:

So, that "rotation path" looks like an arc around an undrawn point, somewhere below the "center point". Is that correct? Will the gun always shoot perpendicular to the arc? (if so what are the gun path and gun ports for)

Or

Can the gun shoot ONLY in those three specific positions through the gun ports? does it move and point only along the gun paths? (If so, what is the rotation path for?)

avatar image Scribe · Mar 07, 2015 at 10:05 PM 0
Share

what do you mean with gun ports? is it like with a canon on a ship, where you align the cannon with openings in the ships side? I don't think I've understood the picture

avatar image boddole · Mar 08, 2015 at 03:27 AM 0
Share

@ Glurth & Scribe:

  • I'll update the origional post but: The gun starts in the "Center Position". When a target is discovered, the gun rotates to face the port that found the target (constrained by the "arc" so that it will stay in the turret housing). Then the gun moves forward to that gun port. When the target is gone or "overridden" by the player, the gun moves back to center, waiting until one of the gun ports finds a new target / or rotates and then moves to the new "active" gun port.

avatar image Scribe · Mar 12, 2015 at 12:41 PM 0
Share

Hey @boddole, are you still looking for an answer, been rather busy lately but can give it a go if you are still needing help!

avatar image boddole · Mar 13, 2015 at 07:57 AM 0
Share

@Scribe:

I think I've got a work-able solution at this point, but thank you for checking back in all the same.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xCiter · Mar 07, 2015 at 05:45 PM

Hey there,

Would this help you at all? :)

 transform.localRotation = Quaternion.Euler(0, Mathf.Sin(Time.realtimeSinceStartup) * 45, 90 ); 
Comment
Add comment · Show 4 · 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 boddole · Mar 08, 2015 at 03:34 AM 0
Share

@ xCiter:

  • Based on feedback, I've updated the original post to (hopefully) be more clear on what I'm after.

avatar image xCiter · Mar 10, 2015 at 12:17 PM 0
Share

Ah right, okay. I think I understand a bit better now. I'm gonna work on this and see if I can get it working for you because off the top of my head, I haven't got a clue. I'd imagine using a ray cast from the gun would be the way to go. Anyway, I'll see what I can do and get back to you ASAP

avatar image xCiter · Mar 10, 2015 at 02:14 PM 0
Share

Hey, I've been working on something...

At the moment, its rough and crude and just down right all over the place XD At the moment, I'm only using one raycast to look through each gun port just to see if I was on the right path. Take a look at the image below..

alt text

Is this sort of what your after? But ins$$anonymous$$d of looking through one gun port at a time, you want however many gun ports there are?

Hope this makes sense xD

avatar image boddole · Mar 13, 2015 at 08:02 AM 0
Share

@xCiter:

At this point, I think I got a work-able solution (but thanks for checking in all the same). To answer your question:

What I'm actually doing is creating a mesh at runtime for each gun port that corresponds to input parameters (like left/right angle, up/down angle, distance, etc), then periodically checking against a list of known target locations to deter$$anonymous$$e if any are within the volume of those triggers.

At that point, the gun rotates to face the port that found a valid target, then moves up to a "firing position" at which point the gun's logic takes over until the target is gone / a better one is found, and it then rolls back to the center, then rotates to face its default rotation.

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

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

Related Questions

Flip over an object (smooth transition) 3 Answers

Distribute terrain in zones 3 Answers

How to make UI screen space image to look at game object in world space 0 Answers

Reletive rotation problems. (C#) 2 Answers

How to rotate towards the mouse on one axis while snapping 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