Help with understanding :Cross()

Hey guys. I’m currently trying to make a wall running system. I researched a bit online, and found this piece of code (which I “enhanced” using undeprecated raycasting)


I understand that the cross product just finds another vector perpendicular to these. I’m having a hard time visualizing which direction this cross is pointing to.

image

Even if it is any of these cross vectors, why would the code need this?
When detecting the part, he set the humanoidrootpart equal to:

hrp.CFrame = CFrame.new(hrp.CFrame.p, Vector3.new(hrp.Position.x - cross.x, hrp.Position.Y, hrp.Position.z - cross.z)

My best guess would be that they’re moving the player back on the x and z depending on where they are facing…?

2 Likes

The right hand rule is a useful thing for direction of the cross product.
right-hand-rule
Vector a is the UpVector of the HRP and b is the normal vector of the wall in this case. (The order of vectors in cross operation matters - left side is the pointing finger and right side is the middle finger and then thumb is the result direction)

Try to figure out which way it’s facing? :happy3:
Answer: In your picture it’s forward if we consider player running forward from the camera on the right side of the shown wall (the red arrow closer to the top)

And to answer your second question: They are just facing the player the right way (the way of the wallrun) since the CFrame is using the cross vector only in the lookAt argument. :happy3:

2 Likes

Thanks for the informative explanation. I’ll be using the finger trick a lot later on :slight_smile:

1 Like