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

How would I rotate a character torso to the face of a brick?

Asked by
Scriptecx 124
6 years ago
Edited 6 years ago

Basically, I'm trying to rotate a character torso to turn towards the face of another brick, making the player parallel to the part. What's the best way to do this?

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

When creating a CFrame using

CFrame.new(pos, lookAt)

it accepts two arguments. The first (pos) is a Vector3 position which is the location of the CFrame. The second (lookAt), is a Vector3 position which, if included, will be the position which the CFrame is facing. Thus, you can use:

lookAt = workspace.LookAtMe.Position
Torso.CFrame = CFrame.new(Torso.Position, lookAt)

The Front face of Torso will now be facing LookAtMe.

EDIT: To make the player parallel to the part, it depends on where the player is relative to the part.

If the "giant, long wall" has its Front face facing towards the player, then:

lookAt = Torso.Position - workspace.LookAtMe.CFrame.lookVector
Torso.CFrame = CFrame.new(Torso.Position, lookAt)

Alternatively, if other faces are facing the player, a different lookAt would be required:

lookAt = Torso.Position + workspace.LookAtMe.CFrame.lookVector --Back facing player
lookAt = Torso.Position - workspace.LookAtMe.CFrame.rightVector --Right side facing player
lookAt = Torso.Position + workspace.LookAtMe.CFrame.rightVector --Left side facing player
lookAt = Torso.Position - workspace.LookAtMe.CFrame.upVector --Top facing player
lookAt = Torso.Position + workspace.LookAtMe.CFrame.upVector --Bottom facing player
0
So, if I was trying to get the player to face a giant, long, wall, would it have the player face the center of the wall or face the wall relative to where I'm standing? Scriptecx 124 — 6y
0
I'm trying to keep the character parallel to the object it's facing, no matter where it is. Scriptecx 124 — 6y
0
This complicates things; in most cases either the part or the player will have to move in order to make the player both facing the part and be parallel to the part. Palhairfreak 71 — 6y
1
Or do you intend to only make the player parallel to the part? Palhairfreak 71 — 6y
View all comments (3 more)
0
I only intend to make the player parallel to the part. Scriptecx 124 — 6y
0
I've updated the answer. Palhairfreak 71 — 6y
0
I would upvote this if I could. Thanks this helped me! henrikknudsen 2 — 4y
Ad
Log in to vote
0
Answered by 6 years ago

Using a BodyGyro might be the easiest way to accomplish what you are trying to do. You can read the wiki page here (The bottom example provides a good demonstration of how it is used): http://wiki.roblox.com/index.php?title=API:Class/BodyGyro

Answer this question