Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 11 Sep 2013 05:12 PM |
I'm trying to get the character to move without the standard controls, or with a BodyVelocity object based on the frame of the camera, like the stand Roblox controls do. Admittingly, I wasn't initially familiar with how this might have worked, so this comes from dissecting free models and help from a friend. The math:
bodyVelocity.velocity = (CFrame.new(0, math.atan2(-1*game.Workspace.CurrentCamera.CoordinateFrame.lookVector.x, -1*game.Workspace.CurrentCamera.CoordinateFrame.lookVector.z), 0)*Vector3.new(x, 0, z)).unit*16
The controls:
mouse.KeyDown:connect(function(key) if key == "w" then y = 1 elseif key == "s" then y = -1 elseif key == "a" then x = -1 elseif key == "d" then x = 1 end end)
A KeyDown negates movement respectively. Any help for me? |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 11 Sep 2013 05:14 PM |
| What is there to help? The mathematics is correct. |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 11 Sep 2013 05:15 PM |
| Oops. Got a little ahead of myself. Yes, the mathematics. I assumed it's wrong. What should I use, or where can i find it? |
|
|
| Report Abuse |
|
|
Bebee2
|
  |
| Joined: 17 May 2009 |
| Total Posts: 3985 |
|
|
| 11 Sep 2013 05:17 PM |
A. Trigonometry
B. Did you define mouse? |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 11 Sep 2013 05:18 PM |
| Wait, the mathematics IS correct? Huh. It behaves odd. Slowing at different angles, and never leaving the same two axes. |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 11 Sep 2013 05:19 PM |
@Bebee2
I have plenty of code to perform my action, I just posted my basic math and control. It works, just not the way I want it. No errors. |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 11 Sep 2013 05:20 PM |
And what is
"A. Trigonometry"
supposed to mean? Can't you clearly see this is what I am using, along with a trig function? |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 11 Sep 2013 05:24 PM |
Let us interpret the BodyVelocity line.
bodyVelocity.velocity = Begins to define the velocity.
(CFrame.new( This will soon be taken as a unit vector.
0, The x-value is 0.
math.atan2(-1*game.Workspace.CurrentCamera.CoordinateFrame.lookVector.x, -1*game.Workspace.CurrentCamera.CoordinateFrame.lookVector.z) Okay, so tan(theta) represents the natural intersection of the hypotenuse and the vector that intersects with the side of the triangle, with an origin of the x-axis, right? So this should the angle at which the tangent has the y-value and x-value have that point of intersection.
,0) The z-value is zero.
*Vector3.new(x, 0, z)).unit*16 This is pretty obvious. The WalkSpeed is 16, taking the unit, et cetera. In essence, the mathematics is correct, but the methodology is not. I might explain tomorrow, if the thread is still going without an answer. I must leave. |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 11 Sep 2013 05:26 PM |
| I know how it works (mostly), I just don't know how I could fix it to behave like I want it to. |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
| |
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 11 Sep 2013 05:53 PM |
| This thread might as well be Absurdism Helpers for me, because it is only he or she that helps me anymore. |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 11 Sep 2013 06:34 PM |
| Bump. Gonna keep bumping until someone helps me. |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
| |
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
| |
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
| |
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
| |
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 12 Sep 2013 07:15 AM |
| Post the full script, first. Then I'll try to mend it. |
|
|
| Report Abuse |
|
|
|
| 12 Sep 2013 10:53 AM |
I cannot tell if this is before or after you PMed me, so I might as well tell you again anyway:
CFrame.Angles, not CFrame.new |
|
|
| Report Abuse |
|
|