Raycasting and crossproduct


I know there’s a way to cross-product the character based on the wall. I’m sort of struggling on cross-product though. If you understand the topic please provide a small piece of code to CFrame the player on the part and leave small notes on it. Thank you very much!

3 Likes

Are you trying to find a vector perpendicular to the surface? In this case you don’t need the cross product as one of the values returned by the FindPartOnRay method is the surface normal of the hit surface.

local hitPart, hitPos, hitNormal, hitMat = game.Workspace:FindPartOnRay(ray)

You can multiply the hitNormal by character size to find the place to position the character.

2 Likes

What does that third parameter return? The orientation? Please provide a full example. Thanks.

It returns a normal of the face that it hit as a unit vector. Imagine it as a line coming off of the face of a part, pointing in the exact same direction as it.

1 Like

Crossproduct is awesome!
Give it two vectors that defines a ‘surface’ and it will return the normal vector of this surface.

Ex: If you have two pencils, point them in any random direction, place a book across the pencils and that’s ur surface. Cross product of those two pencils will return a vector point up from the book.

But if you’re going to cframe the character to the surface you can just use the returned normal from a raycast as Extreme said.

5 Likes

post revoked as old information

I just made this demo which features some grey stuntmen casting rays and then orienting themselves to what the rays hit. There’s a bit of math involved. It’s 1AM here, but I’ll let you have a look and can give you a play-by-play of what’s going on tomorrow. In short, just orienting a character to a surface normal is easy, the much harder problem is what direction should they most naturally face once re-oriented, based on how they were supposed to have arrive there (and from where). Please excuse the TweenService epic hacks, I don’t think tween service can tween a model via SetPrimaryPartCFrame(), or and least I don’t know how, so I tweened some value objects. Had I known I’d need to hook up to RunService, I’d have just skipped TweenService altogether and used CFrame:lerp().

ParkourForDummies.rbxl (23.1 KB)

3 Likes
local rightvector = hitNormal:Cross(Vector3.new(0,1,0))
local frontvector = hitNormal:Cross(rightVector)
dummy.HumanoidRootPart = CFrame.new(hitPos, hitPos + frontvector)

Does that work?

3 Likes

Those are both supposed to be Cross products, right?

Lol my bad :stuck_out_tongue:

1 Like