|
| 14 Aug 2014 12:45 PM |
I want the effect of the player facing the mouse like in Dungeon Delver, while walking on the ground. I tried using BodyGyro, but the closest I got was getting the part to face the same direction as the mouse.
What specifically should I do to accomplish this? |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 14 Aug 2014 08:39 PM |
Here I made this http://www.roblox.com/Point-towards-mouse-item?id=172134435 |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 14 Aug 2014 09:12 PM |
You could like, use MoveTo() with the model O:
sel = nil
tool.Equipped:connect(function(mouse) sel = true while sel == true do playermodel:MoveTo(playermodel.Position,mouse.Hit.Position) wait() end tool.Unequipped:connect(function() sel = false end) end) |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 12:34 PM |
| Thanks for the model! Can you explain how it works? |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 02:25 PM |
You mean how to use it? Just put it in workspace.
How it works? Well, first I get the vector 'dir' from the torso to the mouse and normalize it (magnitude=1). Then, I find the angle 'dir' makes with the positive ( I think) Z-Axis by doing math.atan2(dir.X, dir.Z)
note: math.atan2(opposite, adjacent) is just atan(opposite/adjacent) but in the right quadrant and handles adjacent being 0 correctly.
Then I just add 180 degrees (or math.pi) to the angle to line it up correctly:
CFrame.new(torsoPos)* CFrame.Angles(0, math.atan2(dir.X, dir.Z) + math.pi, 0) |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 03:11 PM |
| Oh ok cool! I don't quite get it, but thanks! Is there an easier method to do this that I can understand better? Why doesn't BodyGyro work for this? |
|
|
| Report Abuse |
|
|
travddm
|
  |
| Joined: 29 Mar 2012 |
| Total Posts: 926 |
|
|
| 15 Aug 2014 03:14 PM |
| BodyGyro *does* work for this.. CFrame.new(torsopos,mouse.Hit) as the CFrame for a BodyGyro with a maxTorque of Vector3.new(0,whateveryouwant,0) |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 03:41 PM |
| I had some issues with BodyGyro when you try to jump, and thought CFrame worked better. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2014 09:40 AM |
| Oh ok thanks a ton! Is there a way to make the player able to jump with BodyGyro? |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 16 Aug 2014 10:17 AM |
@nicemike That sounds overcomplicated. I think this would work just as well:
_, y = CFrame.new(Character.Torso, Mouse.Hit.p):toEulerAnglesXYZ() Character.Torso.CFrame = Character.Torso.CFrame * CFrame.Angles(0, y, 0) |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2014 11:21 AM |
| Oh ok lol, I get that fully besides the toEulerAnglesXYZ() part, what does that do? |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2014 11:27 AM |
It's much simpler than any of this. Did you know that if you use CFrame to move or rotate a part, anything welded or joined to it will follow?
Your Torso is joined to all of your other body parts. All you have to do is this:
Torso.CFrame = CFrame.new(Torso.Position, Vector3.new(Mouse.Hit.p.x, Torso.Position.Y, Mouse.Hit.p.z))
When you do CFrame.new(Position1, Position2), it will make a new CFrame where the part is put at Position1 and LOOKS AT Position2.
I did Vector3.new(Mouse.Hit.p.x, Torso.Position.Y, Mouse.Hit.p.z)) where Position2 is so it would only make your torso turn, and not look up or down. You don't want it to look down or up, but only need it to turn left or right. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2014 12:51 PM |
That's probably easier to understand, I just prefer my way as a stylistic choice.
BTW, if you do yours correctly (localize all variables), it's just over 1% faster than mine because it's C-side. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2014 12:54 PM |
| Scratch that, which one is faster changes erratically. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2014 01:18 PM |
| OMG than you so much it worked AND I understand it fully lol. Thanks! |
|
|
| Report Abuse |
|
|
travddm
|
  |
| Joined: 29 Mar 2012 |
| Total Posts: 926 |
|
|
| 28 Aug 2014 11:51 AM |
| BodyGyro would and does work fine, you simply have to set the P(Power) and D(Dampening) to integers that work nicely with each other. |
|
|
| Report Abuse |
|
|
| |
|