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.
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.
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.
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)
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.
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!