Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

Can I use Cframe to move the player forward in the direction of the camera?

Asked by
Hero_ic 502 Moderation Voter
10 years ago

Basically what I am trying to do Is now that I have gotten rid of HumanoidController and I decided to start my own HumanoidController" but I do not know if it is possible to use Cframe when key == 'w' so that once the player does this it will move you forward in the camera direction using Cframe. I think this is possible but I do not know for sure. :/

Hope there is some explanation to this.

001repeat wait(1/60) until game.Players.LocalPlayer.Character and 
002game.Workspace.CurrentCamera
003repeat wait(1/60) until game.Players.LocalPlayer.Character:FindFirstChild("Torso")
004 
005local Camera = game.Workspace.CurrentCamera
006local Torso = game.Players.LocalPlayer.Character.Torso
007Camera.CameraType = "Scriptable"
008Camera.CameraSubject = nil
009 
010repeat wait() until game.Players.LocalPlayer:FindFirstChild("PlayerGui")
011 
012local Player = game.Players.LocalPlayer
013local size = Instance.new("ScreenGui", Player.PlayerGui)
014size.Name = "Size"
015 
View all 116 lines...
0
Use the lookVector CFrame constructor of the CurrentCamera's CoordinateFrame Property. Goulstem 8144 — 10y
0
Sorry i'm kinda new to coding so I need a bigger explanation? Hero_ic 502 — 10y
0
Can't you use the Move method of the Humanoid to do what you're doing? http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Move Spongocardo 1991 — 10y

3 answers

Log in to vote
3
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

What You Need To Do

You need to CFrame the Character's Torso relatively to itself, but with an offset of however much you want to move them multiplied by the lookVector of the Camera's CoordinateFrame.

Code

Expected to be in a LocalScript

01wait(1)
02 
03local cam = workspace.CurrentCamera
04local plr = game.Players.LocalPlayer
05local tor = plr.Character:WaitForChild('Torso')
06 
07--Relatively to itself
08tor.CFrame = tor.CFrame
09            --How much you want to move them
10            * CFrame.new((CFrame.new(0,0,-1)
11            --Multiplied by lookVector of the Camera's CoordinateFrame
12            * cam.CoordinateFrame.lookVector * 1))
Ad
Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
10 years ago

You can always use the Move method of Humanoid.

Move (Vector3 moveDirection, bool relativeToCamera)

The first argument is just the the Vector3, or 3D point in the place, or position you want your *humanoid *(player) to head towards until interrupted by the pressing of keys or a certain object

The second argument is set to false by default setting it to true would mean allowing the movement of the player to in relation or proportion to the Camera

1local player = game.Players.LocalPlayer
2local character = player.Character or player.CharacterAdded:wait()
3local humanoid = character:WaitForChild('Humanoid')
4 
5humanoid:Move(Vector3.new(45, 0, 45), true)
Log in to vote
0
Answered by
iLegitus 130
10 years ago

Well,Im getting it that you want the player to move into the direction the camera is focusing on.

Well,A decent explenation is,Just make the camera move/focus on whatever brick you want,And then make another part that you want the player to walk to and use the :MoveTo() on the player's humanoid (MoveTo() to the position of the part you want the player to walk into),But be sure to disable the player's control or just while true do it and then break the code once the player is there.

Answer this question