playMaker

Author Topic: Complex Turret rotation [SOLVED]  (Read 5459 times)

TonanBora

  • Playmaker Newbie
  • *
  • Posts: 11
Complex Turret rotation [SOLVED]
« on: June 18, 2014, 07:49:40 PM »
Okay, so I have a Turret that has two parts: The Base, and the Gun.
The Base should only be able to rotate along its Y axis (left and right)
The Gun should only rotate along its X axis (up and down).
I currently have an Empty Game object set up as a container for both the Base and Gun.  The Gun is a child to the Base so that it will rotate as the Base does.

I am trying to figure out a way to get the Base AND the Gun to rotate so that the Gun can point at its target.

Any ideas?

I have tried Smooth Look At, as well as Jean's Smooth Look At 2 with limited success.
« Last Edit: June 24, 2014, 10:28:13 AM by TonanBora »

TonanBora

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Complex Turret rotation
« Reply #1 on: June 18, 2014, 08:20:01 PM »
This is a picture of the turret in question:

TonanBora

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Complex Turret rotation
« Reply #2 on: June 20, 2014, 04:57:34 PM »
If this problem as been solved before, I would love a link! :)

cwmanley

  • Full Member
  • ***
  • Posts: 107
Re: Complex Turret rotation
« Reply #3 on: June 22, 2014, 12:58:31 AM »
Hello,

This is just one simple solution that will break at high speeds. You could use the Smooth Look at or the Set Rotation Actions for better results.

Thanks

TonanBora

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Complex Turret rotation
« Reply #4 on: June 22, 2014, 01:21:48 PM »
Hey there maxblah! :)

Smooth look does not work, as this is a side mounted turret. I have had more luck with Jean's Smooth look at 2, which works great for the Base.  However, SLA 2 does not work well for the Gun, as it fights against the Base's rotation.

The other problem with SLA and SLA 2 is that if the ship rotates, the turret keeps its own rotation and does not rotate with the ship despite the fact that the turret is parented to the ship.

How would I use set rotation? 
« Last Edit: June 22, 2014, 01:27:41 PM by TonanBora »

cwmanley

  • Full Member
  • ***
  • Posts: 107
Re: Complex Turret rotation
« Reply #5 on: June 22, 2014, 07:46:43 PM »
Hello TonanBora,

I should have paid more attention to the picture.

With the Get and Set Rotation Actions you can choose which axis you want affect.

Maybe you can have a dummy object with one of the look at Actions and get the rotation values of it, so you can delegate the xyz to the base and the gun.

Please let me know what you come up with, I am interested.

Thanks

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Complex Turret rotation
« Reply #6 on: June 22, 2014, 09:36:22 PM »
One thing to consider is that smooth look at works with Z forward and by default world y vertical. You need to check (and may have already) to make sure z points down the barrel. You may also need to establish a different up axis.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Complex Turret rotation
« Reply #7 on: June 23, 2014, 03:32:56 PM »
I think you might be overthinking it. I just setup a turret using a Base and Cannon with a Smooth Look At action on each and it works fine. The key is to use Keep Vertical on the base so it only rotates around Y. See attached images.

If you want to use a different lookat speed on the cannon, you could use Set Rotation to fix the rotation in Late Update, forcing it 0 relative to the Base.

« Last Edit: June 23, 2014, 03:35:35 PM by Alex Chouls »

TonanBora

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Complex Turret rotation
« Reply #8 on: June 23, 2014, 09:43:46 PM »
I would like to thank all you for chipping in, I appreciate this.
To Alex Chouls:
The Base does quite well with Smooth Look At, my main problem is getting the Cannon to rotate properly.
What I want is for the Cannon to rotate along with the base, but continue to look at the target.
This means that the cannon needs to rotate along its Y axis to keep it in line with the Base, while rotating along its X axis to try to line up with the target.

To give all of you a better perspective on the turret, I have taken a few more pictures of it.

Notice in the pictures that the base has two braces that the cannon fits between, I need the cannon to stay in line with those braces while the Base rotates.

Another problem I have is that if the ship rotates, the turret keeps its starting rotation (see the last picture)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Complex Turret rotation
« Reply #9 on: June 23, 2014, 11:47:20 PM »
Have you tried Smooth Look At with a Set Rotation action to zero out rotation around the axis that it's not allowed to rotate around, like in the last screenshot above?

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Complex Turret rotation
« Reply #10 on: June 24, 2014, 01:13:17 AM »
I actually hacked it close doing pretty close to what Alex says. I got the base working by getting the transform.up vector 3 of the root object(spaceship for you) and applying it to the smooth look at up vector and then using a set rotation every frame zeroing out the x angle with a late update. For the turret I used a smooth look at and just used a set rotation to zero out the y and z axis again with a late update. It was not perfect but very close.
« Last Edit: June 24, 2014, 01:15:00 AM by redikann »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Complex Turret rotation
« Reply #11 on: June 24, 2014, 10:01:03 AM »
I meant to get to this one sooner but I've been sick for a few days.

Here's an example scene. I think this is what you're looking for, the rotation for the Base and the Gun are separate lock angles so you just have to set them to 0 with a Look action controlling the last, unlocked angle. Doing so in self space allows you to put the turret as a child of any moving or rotating object and it'll still keep its lock angles correctly.

Just play around with moving/rotating the big box and the target box. Next you need to handle angle clamps ;)
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

TonanBora

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Complex Turret rotation
« Reply #12 on: June 24, 2014, 10:27:21 AM »
I have tried the Set Rotation, and it works perfectly!
It even fixed the ship rotation problem.
\0/
Thanks Alex & Lane. :)