- Home /
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.
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?)
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
@ 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.
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!
I think I've got a work-able solution at this point, but thank you for checking back in all the same.
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 );
@ xCiter:
Based on feedback, I've updated the original post to (hopefully) be more clear on what I'm after.
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
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..
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
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.