The Ultimate Guide to Vector3:Cross() and Vector3:Dot()

I have the perfect solution NTAB:

What I would do is every RenderStep, calculate the Dot between: lastStepAirplaneLookVector and currentStepAirplaneLookVector.

(Excuse the unformatted code, I’m on my phone lol)

function renderStep()

    local currentStepAirplaneLookVector = plane.CFrame.LookVector

    local dot = lastStepAirplaneLookVector and lastStepAirplaneLookVector:Dot(currentStepAirplaneLookVector)

    lastStepAirplaneLookVector = currentStepAirplaneLookVector
end

Then, rotate the airplane by doing:

local rollAngle = (1 - dot) * rotateIntensity

However, this will roll the airplane in only one direction, regardless of which direction the airplane is turning.

We will need to add one more thing to make sure it rolls in the correct direction:

local _, currentY = currentStepAirplaneLookVector:ToEulerAnglesYXZ()
local _, lastY = lastStepAirplaneLookVector:ToEulerAnglesYXZ()

local rollDirection = math.sign(currentY - lastY)

Ok, we finally have everything we need!

function renderStep()

    local currentStepAirplaneLookVector = plane.CFrame.LookVector

    local dot = lastStepAirplaneLookVector and lastStepAirplaneLookVector:Dot(currentStepAirplaneLookVector) or 1

    local _, currentY = currentStepAirplaneLookVector:ToEulerAnglesYXZ()
    local _, lastY = lastStepAirplaneLookVector:ToEulerAnglesYXZ()

    local rollDirection = math.sign(currentY - lastY)

    local rollAngle = (1 - dot) * rotateIntensity * rollDirection

    lastStepAirplaneLookVector = currentStepAirplaneLookVector
end

You may have to do some adjusting of which angle to use, for example you may need to get difference of the X or Z angles instead of the Y angles, and you might need to multiply the rollDirection by -1 if the direction the plane rolls in is flipped - I’m only saying this cause I’m on my phone and haven’t tested any of this, but it should work :nerd_face:

1 Like

can this work on a character body?

1 Like

It will work on any model, just make sure to use the PrimaryPart or any specific part to get the model’s CFrame

1 Like

what is rotateIntensity and lastStepAirplaneLookVector what would i make those

1 Like

You should add Vector3:Angle() I didn’t even know it existed before today…

2 Likes

i think you should fix

Blockquote

CamLookVector:Dot(BlockLookVector)

Blockquote
i dont get it

Given a look vector how do I find the other basis of the space (right/upvector)

You need two vectors, it’s impossible to find the other two vectors with just one.

2 Likes

why not?, Isn’t that what they do in CFrame.lookat?

what I am trying to do is a climbing system and I want the Arm of an r5 Character point at an attachment placed in the climbing bar something like this:

I already have the points position on the climbing, But I am not sure how to rotate the arm correctly, also I can’t assume things like look vector = Vector3.new(0,1,0) because that’s not what I am trying to do.

Katrist is correct with this, there technically an infinite amount of possibilities for a RightVector and UpVector if only the LookVector is specified. That being said, for what your trying to do metatab1e, your going to want to get a Unit vector from the position of each arm to the position on the bar, then mess with the C0 value until it points in the right direction. A lot of the C0 stuff is just trial and error until it works lol

1 Like

I have no idea on how to randomly position the c0 using the direction vector and get a good result, every result I got is very ugly, also I get it there is an infinite possible values but for my purpose isn’t there a way to restrict the possible values?

Thanks for this, this is SUPER useful actually.

For fun I once wanted to brainstorm and figure out how I could possibly make a custom character mover/physics model and have the character rotate or change their local gravity when running up a wall for example.

But one issue I ran into was that rotating the character would be difficult without unintended side effects.

Ideally when a character’s direction of gravity and movement changes, you’d want them to be able to keep walking in a straight line while the gravity change happens.
What I was missing was figuring out on what axis or “imaginary beam” I’d have to rotate the character.

When a character runs up a wall, the floor is their old down vector, and the wall will be their new down vector.
And now I know I can just use cross product to smoothly rotate the character so they can keep running in a straight line relative to the camera/view.

2 Likes

Thank you for the patience with your response metatab1le, from the looks of what your trying to do, for the right arm, I recommend you find the Unit from the RightGripAttachment to the position on the bar, and make that Unit a cframe with CFrame.lookAt(Vector3.new(), unit), and multiply the original C0 with that. Just repeat this for the left arm.

damn, i really appreciate your the effort your put in this post to make stupid people like me comprehend the use of that. thanks for reminding me of these. i really like how simple the tutorial is, but i will still forget lol

1 Like

haha its all good :joy: I appreciate the support :pray:

1 Like

ma mind: explodes with 1 million intensity

2000iq moment: occurs

1 Like