|
| 29 Aug 2016 08:43 PM |
I have this tank, which the turret moves independently to the body of the tank. I've made it so the turret follows where your mouse moves, however when you rotated the tank the turret would point the wrong direction (Via how HingeConstraints work), so I decided to subtract the angle the base is moving from the angle of the turret, and it worked perfectly. Somewhat. See when I would get the angle from the body of the tank, it wasnt based off of a 360 angle like hingeconstraints are. They get the angle from Eular angles which are yucky.
So when I do this, tank.Constraints.TurretHinge.TargetAngle = Y - 90 - tank.Base.PrimaryPart.Rotation.Y
It only works when the tank's rotation is less than 90 and greater than -90, because it never went above that number. So instead of doing what is exspected, it returned this as the angles value. 0 = 0 45 = 45 90 = 90 135 = 45 180 = 0 270 = -90
Which caused my tank to point in the completely wrong direction half of the time, and I honestly have no idea how to fix this anymore because I've been trying for hours. See it first hand: https://www.roblox.com/games/486473956/Tank-Trouble |
|
|
| Report Abuse |
|
|
Real_Edgy
|
  |
| Joined: 23 Oct 2013 |
| Total Posts: 1212 |
|
|
| 29 Aug 2016 08:44 PM |
| 270 should return -90, considering roblox goes from 180 to -180 if i remember correctly. Or something along those lines. |
|
|
| Report Abuse |
|
|
|
| 29 Aug 2016 08:44 PM |
Let me explain some of my code, sorry I forgot.
local diff = mouse.Hit.p - tank.Turret.PrimaryPart.Position --This zeros it onto the x axis local Y = math.deg(math.atan2(diff.X,diff.Z)) -- This turns that data into an angle in degrees with atan2 tank.Constraints.TurretHinge.TargetAngle = Y - 90 - tank.Base.PrimaryPart.Rotation.Y -- This takes that angle, subtracts 90, and then subtracts the tanks rotation. |
|
|
| Report Abuse |
|
|
|
| 29 Aug 2016 08:45 PM |
| No number returned was greater than 90 or less than -90, Because im getting it from the rotation.Y of the part |
|
|
| Report Abuse |
|
|
|
| 29 Aug 2016 08:46 PM |
| ################################################## |
|
|
| Report Abuse |
|
|
| |
|
|
| 29 Aug 2016 08:53 PM |
| Jared, are you going to try to help again? Please? lol |
|
|
| Report Abuse |
|
|
|
| 29 Aug 2016 09:00 PM |
Quite the opposite. I can't tell whether it censored me because it was all caps for over-dramatic effect, or whether it was "fool". I'm guessing the former.
Whatever, Euler rotations are wrong and cause problems, especially here when you're using global space where you should be using local, but I suppose that isn't Euler's problem.
I don't know exactly what you need. Is this rigged with a Motor6D or something?
|
|
|
| Report Abuse |
|
|
|
| 29 Aug 2016 09:05 PM |
a HingeConstraint connects the turret of the tank to the body. It has a rotation property that lets you turn it to a certain degree, e.g, Im using it to point at the cursor.
I've gotten the correct angle I needed using this, local Y = math.deg(math.atan2(diff.X,diff.Z))
However when you spin the entire tank, the turret moves too and is off by the same angle the tank is. So my solution was to simply subtract the angle of the base.
tank.Constraints.TurretHinge.TargetAngle = Y - 90 - tank.Base.PrimaryPart.Rotation.Y
However this angle isnt based off 360, Its based off Something else, Which doesnt work.
So my end question is how would I find the true angle the tank is facing? |
|
|
| Report Abuse |
|
|
|
| 29 Aug 2016 09:19 PM |
MWAHAHAH I was able to fix it by using atan2 again (ily atan2)
local diff = mouse.Hit.p - tank.Turret.PrimaryPart.Position local angle = math.deg(math.atan2(tank.Base.PrimaryPart.CFrame.lookVector.X,tank.Base.PrimaryPart.CFrame.lookVector.Z)) local Y = math.deg(math.atan2(diff.X,diff.Z)) tank.Constraints.TurretHinge.TargetAngle = Y + 90 - angle tank.Constraints.GunHinge.TargetAngle = 90 |
|
|
| Report Abuse |
|
|
sayhisam1
|
  |
| Joined: 25 Nov 2009 |
| Total Posts: 2092 |
|
|
| 29 Aug 2016 09:27 PM |
What is with the sudden influx of tank related things? I am making my own tank game too.. https://www.roblox.com/games/485169061/Tank-Warfare |
|
|
| Report Abuse |
|
|
|
| 29 Aug 2016 09:27 PM |
| Ive just always wanted to make a tank and I wanted to use the new constraints |
|
|
| Report Abuse |
|
|