generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Object rotation to face twords mouse position

Previous Thread :: Next Thread 
Tanker273 is not online. Tanker273
Joined: 25 Mar 2011
Total Posts: 57
05 Apr 2015 06:26 PM
I am trying to build some tanks and stuff (which has gone well) but I am trying to get a code to rotate the turret head (which freely rotates w/ welded gun to it) and I can't get anything to work. I've had a code get the X, Y and Z or Mouse.Origin and plug those numbers into a BodyVelocity, BodyGyro and several others inside the central turret part, but nothing works. Can anyone help?

BTW, this was the code mentioned above (As a local script in the player's backpack) (I know it's probably a mess):

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.Button1Down:connect(function()
print("Button 1 is down")
print(Mouse.Origin)
game.Workspace.AMX_50b.Turret.WeldToTurret.TurretHeadUnion.BodyGyro.cframe = Vector3.new(Mouse.Origin.X, Mouse.Origin.Y, Mouse.Origin.Z)
end

P.S, as I said, it plugs in the numbers fine, but the closest I got was a BodyGyro only rotating the turret head to (0, 0, 0), with no change in sight.

P.S.S, If you wanted to see said tank, here it is: http://www.roblox.com/AMX-50b-No-working-gun-yet-item?id=234322263
Report Abuse
DrMathematica is not online. DrMathematica
Joined: 29 Aug 2008
Total Posts: 27268
05 Apr 2015 06:41 PM
game.Workspace.AMX_50b.Turret.WeldToTurret.TurretHeadUnion.BodyGyro.cframe = CFrame.new(workspace.AMX_50b.Turret.WeldToTurret.TurretHeadUnion.Position, Mouse.Hit.p)
Report Abuse
Tanker273 is not online. Tanker273
Joined: 25 Mar 2011
Total Posts: 57
05 Apr 2015 06:53 PM
This does work, in a sense. It attempts to move the turret, but just thrusts it in the given direction as opposed to rotating in said direction. I just tried to play with it a bit, moving the desired rotating part to the muzzle at the end of the barrel, but now the barrel swings wildly, and I might be able to fix it, but the current mesh I am using for the muzzle, it dictates a need for a specific rotation, which doesn't agree with the new positions added to the bodygyro.
Report Abuse
Tanker273 is not online. Tanker273
Joined: 25 Mar 2011
Total Posts: 57
05 Apr 2015 07:14 PM
I actually may have just got it working. It is still very glitched and jittery, and does not like to aim up, but I played whit the code a bit and had to edit the tank model itself so the turret part this script was operating off of was facing forward, not left. Thanks for the help.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image