of     1   

stroudie
#117989492Saturday, November 16, 2013 1:41 PM GMT

I'm currently trying to make a turret that rotates with the movement of the mouse. The turret is on top of a tank, and the turret movement is done with a weld between itself and a fixed point on the tank. My problem is that I can't work out what existing values (the lookVector of the Engine, the lookVector of the turret etc) to use, and how to use them to point the turret correctly. Only one axis needs to be affected, so the turret just turns to face any side of the tank. I have set up all of the parts facing the right directions, to make things easier (front of parts facing the front etc). I need to know how to keep the turret pointing in the direction of a players mouse, no-matter the direction that the tank itself is facing in. If anyone can help, it would be appreciated. If this description's confusing, let me know. Currently with the script I have the following, which only lets the turret point within a certain range infront of the tank, whilst the tank is facing forward in relation to the map: MWeldX.C1 = CFrame.new() * CFrame.Angles(0,Mouse.Hit.lookVector.x,0)
stroudie
#117992332Saturday, November 16, 2013 2:36 PM GMT

b1
stroudie
#118011051Saturday, November 16, 2013 6:18 PM GMT

b2
Scubadoo2
#118011915Saturday, November 16, 2013 6:28 PM GMT

I had this same problem trying to make my own tank. You need to convert the mouse hit to the turrent by doing turrent.CFrame:pointToObjectSpace(Mouse.Hit) and then taking the desired vector out of that. ...I think. I'm not at the computer now so I can't double-check at the moment. Please say if it works or not.
TimeShop
#118012185Saturday, November 16, 2013 6:31 PM GMT

Wouldn't just creating a lookVector be good enough? CFrame.new(Tank.Position, mouse.Hit.p)
stroudie
#118012718Saturday, November 16, 2013 6:37 PM GMT

Using... MWeldX.C1 = CFrame.new() * CFrame.Angles(0,MainPart.CFrame:pointToObjectSpace(Mouse.Hit.lookVector).x,0) The turret just spazzed out. Did you mean it in some other form?
stroudie
#118012815Saturday, November 16, 2013 6:38 PM GMT

@TimeShop, No, because welds work in relation between two parts, not the world. That would only work whilst the vehicle is facing a certain way.
Scubadoo2
#118040412Saturday, November 16, 2013 11:29 PM GMT

Woops... yep, I meant it in some other form. How I did it with my tank is this: ---- engine:findFirstChild("Weld").C0 = CFrame.new(Vector3.new(welded.x, welded.y, welded.z), engine.CFrame:pointToObjectSpace(target)) ---- This works perfectly, no matter how much it turns. What you were asking was a little tricky but I figured it out. Just tried it out so this should work: ---- it = engine.CFrame:pointToObjectSpace(target) MWeldX.C1 = CFrame.new(Vector3.new(0,0,0), Vector3.new(0,it.y,it.z)) ---- If this movement isn't what you are looking for then mess around with the second Vector3. Hopefully it works.
stroudie
#118051565Sunday, November 17, 2013 1:26 AM GMT

Thanks.
Ictis
#118063056Sunday, November 17, 2013 3:31 AM GMT

Does that actually working considering that the weld is subjective to its part 0? I tried something similar and figured it spazzed out because I was changing the weld, not the actual CFrame of the part.
Beardjaculation
#118063480Sunday, November 17, 2013 3:36 AM GMT

Wouldn't it just be easier to set the position of the turret atop the tank with CFrame's, and to change the rotation with CFrame's every 0.01 second?
Ictis
#118063924Sunday, November 17, 2013 3:41 AM GMT

Easier? Yes. Not so much in terms of efficiency or looks (it will stutter horribly).
stroudie
#118090552Sunday, November 17, 2013 1:14 PM GMT

The method didn't work. I eventually just changed it so that the turret uses the A and D keys to rotate by 5 degrees as fast as it can (doesn't stutter).
stroudie
#118090611Sunday, November 17, 2013 1:15 PM GMT

For this turret I think it actually works better like that. The turret user doesn't also drive the vehicle, or fire the main guns.
Private17
#141297404Wednesday, July 23, 2014 7:08 PM GMT

Is this scripting?, All I know I need to know how to script and CFrame and everything is all better. :/

    of     1