Yeah ofc, just use:
local vectorA = Vector3.new(0, 1, 0)
local vectorB = Vector3.new(0, 0, -1)
local yourVectorC = vectorA:Lerp(vectorB, 0.5).Unit * vectorA.Magnitude
print(yourVectorC)
Yeah ofc, just use:
local vectorA = Vector3.new(0, 1, 0)
local vectorB = Vector3.new(0, 0, -1)
local yourVectorC = vectorA:Lerp(vectorB, 0.5).Unit * vectorA.Magnitude
print(yourVectorC)
Finally, a good tutorial explaining :Cross() and :Dot(), really good guide (also your rocket building skills are 10x better than mine)
preciate that bro!
charactacter30
I give you a whopping 1000/10 of your explanation
Yes it will be 0.5 if the angles are 45 from each other and -0.5 if the angles are 135 degrees from eachother (135 is just the flipped version of 45)
I made a car, and I would like to detect next waypoints, the car moves by waypoints, if the next way point is to the right side of car, car should turn right
How do I detect if the waypoint is right side of the car
Ok this actually doesn’t even need to use Dot, what you can do is just number the waypoints in order and then tween the car to the next waypoint.
No like, the car moves through tween, but the thing is, the steering inside the car should also move like auto pilot, so I need to detect left or right the car moves in order to find which side its going
How do I do it?
You can use dot product to find the angle, and cross product to find the direction left or right.
Ex from Sleitnick is AngleBetween signed:
local function AngleBetween(vectorA, vectorB)
return math.acos(math.clamp(vectorA:Dot(vectorB), -1, 1))
end
local function AngleBetweenSigned(vectorA, vectorB, axis)
local unsigned = AngleBetween(vectorA, vectorB)
local cross = vectorA:Cross(vectorB)
local sign = math.sign((axis.X * cross.X) + (axis.Y * cross.Y) + (axis.Z * cross.Z))
return (unsigned * sign)
end
It does not work either it gets the correct angle
Well that is the simplest explanation of cross and dot I have ever seen. Incredible.
Great job, best tutorial on the devforum by far.
I appreciate it dude!!
This is enough chrar
I really used to think these are complicated and for crazy good scripters who know what they are doing but turns out its simple as heck ty man have a great life!
hi i was wondering if you knew how to find if the player is going down a slope, I need it to make the player go faster when they are sliding down a slope. this is what I have but what would go in the NORMAL part of the script
local incline = Vector3.new(1, 0, 0):Cross(Vector3.new(NORMAL)
if incline.magnitude == 0 then
incline = Vector3.new(1, 0, 0)
end
local angle = math.acos(Vector3.new(0, 1, 0):Dot(incline))
if angle > math.pi / 1.5 then
print("Angle")
Slide.Velocity = angle * Slide.Velocity * 1.15
else
print("No Angle")
Slide.Velocity = Slide.Velocity * 0.99
end
Ok so this is a perfect example of somewhere where you can utilize Dot, and I love the way you did it in your code. Personally, I would just use a raycast from your HumanoidRootPart directly downward and then just use the normal from that.
(
local ray = workspace:Raycast(HRP.Position, Vector3.new(0, -hipheight - 1, 0), params)
local normal = ray and ray.Normal
)
thank you so much i will try that
Its not working but im pretty sure this is my fault, as I’m very new to raycasting I think my variables are off.
local HumanoidRootPart = Character.PrimaryPart
local HipHeight = Humanoid.HipHeight
local Params = RaycastParams.new()
local ray = workspace:Raycast(HumanoidRootPart.Position, Vector3.new(0, -HipHeight - 1, 0), Params)
local normal = ray and ray.Normal
local incline = Vector3.new(1, 0, 0):Cross(Vector3.new(normal))
if incline.magnitude == 0 then
incline = Vector3.new(1, 0, 0)
end
local angle = math.acos(Vector3.new(0, 1, 0):Dot(incline))
if angle > math.pi / 1.5 then
print("Angle")
Slide.Velocity = angle * Slide.Velocity * 1.15
else
print("No Angle")
Slide.Velocity = Slide.Velocity * 0.95
end
Ok yes do for the raycast, you will want to include an ignorelist. Do it like this:
local params = RaycastParams.new()
params.FilterDescendantsInstances = {player.Character}
params.FilterType = Enum.RaycastFilterType.Blacklist
ok thanks im trying it out now