I'm struggling with CFrame!

Is this not what you’re looking for?

Yes, I want it to be like the image I put on the post.

I don’t get it, it keeps teleporting the player underneath the baseplate. I’m using the Orientation but it’s not working?

I don’t understand—the video I posted uses the code I posted earlier.

It works fine for me.

Are you asking how to face the closest surface of a part, instead of the part’s position, maybe?

Actually, I figured it out. The question regards about trying to get the player to face away from the normal of a surface, while it’s still standing. The angle should be a right angle against the normal.


Like this, I want it to be facing the same direction as the part. I’m using the parts RightVector to spring them into the next part. I can’t rotate the player the same way though.

humanoidRootPart.Velocity = Vector3.new(part.CFrame.RightVector.X * 60, 50, part.CFrame.RightVector.Z * 60)

You are just going to have to do this;

CFrame.Lookat(HumanoidRootPart.Position, Vector3.new(-part.Position.X,HumanoidRootPart.Position.Y,-part.Position.Z))-- negative so it would make you look the other way try *-1 just in case it won't work.

Oh, there’s the issue: You need this to always align right against the normal, not the center of the part.

@ASimpleGalaxy I think raycasting would be necessary to find the right surface you are contacting and using the information of where the ray hit would give you a normal. I reckon it would work almost like laser beams.

Then they are going to have to raycast.

1 Like

Using CFrame.new() to make something face something is deprecated, and is recommended to use lookAt()

1 Like

How exactly would I use raycasting because I’ve never used it before and I’m trying it, but still getting the same result. I’m plugging it into the CFrame but it still gives the same numbers, I don’t understand. I’m using the normal property of what it says.

Why does it keep making the character diagonal to the part?

If you read my statement previously, the positional vector on the part is the middle of the entirety, therefore it positions diagonally against it.

For raycasting, that’s something you should probably invest some time exploring and testing. Try something less complicated without the character or anything to connect with.

1 Like

Will do. Thanks for all your help and patience.

Ohhh that’s much different than what I thought.

If you can always assume you’re jumping toward the RightVector you can just do

local back = part.CFrame.RightVector
local up = humanoidRootPart.CFrame.UpVector
local right = up:Cross(back)
humanoidRootPart.CFrame = CFrame.fromMatrix(humanoidRootPart.Position, right, up)

If you don’t know which surface you’ll be jumping on, you’ll need to do more complicated things like raycasting to determine the surface. I have a post that might help with that here: Edge Detection from Mouse - #23 by nicemike40

Also… you could just make the player face in the same direction as it’s velocity:

local almostBack = -humanoidRootPart.Velocity.Unit
local up = humanoidRootPart.UpVector
local right = up:Cross(almostBack)

humanoidRootPart.CFrame = CFrame.fromMatrix(humanoidRootPart.Position, right, up)
1 Like

Well, this works perfectly and it’s simple enough. Thanks so much!

I think at @nicemike40 solution would work.
However there is a much easier way without adding all the extra complexities ( especially the cross product, try to avoid that nasty operation whenever possible)

The solution just uses CFrame.lookAt, by adding the direction of the RightVector of the onto our position vector for the hmrp, but making sure to project that rightvector onto the xy plane by just dropping the y component.

game:GetService("RunService").Heartbeat:Connect(function()
	local cf = part.CFrame.RightVector * Vector3.new(1,0,1)
	
	local pos = character.HumanoidRootPart.Position
	character.HumanoidRootPart.CFrame = CFrame.lookAt(pos,cf+pos);
end)

Okay, so I did some messing with this and it’s this simple. I had no idea what Vector3:Cross from what @nikemike40 said does until I looked it up. No point in using it when you can just use what is already given. Anyways thanks for everyone’s help and patience. This went on for way too long and was way too confusing.

humanoidRootPart.CFrame = CFrame.fromMatrix(humanoidRootPart.Position, part.CFrame.LookVector * -1, humanoidRootPart.CFrame.UpVector)
1 Like

A cross product is just a couple of multiplications and additions.

CFrame.lookAt internally uses a cross product, also. But your code might be easier to read and understand, so it might be better!

1 Like

You could indeed do that :slight_smile:

I didn’t just because to be “nice” to fromMatrix you should ensure that your vectors are 90 degrees to each other—in this case, the part’s LookVector and the humanoid’s UpVector might not be.

Although ROBLOX will try its best to fix it for you anyways, so I like your code anyways because it’s simpler to read!

1 Like

It’s not nasty because of its computation, I was more expressing its nasty in its non-communicative factor.

But I understand what you are saying, and yes you are correct that in the background I guess CFrame.lookAt uses the cross product to build the matrix anyways.