Raycast normal and CFrame.lookAt problem

Hi, I’m Sop (a newbie scripter).

I have a problem with CFrame.lookAt() orientation is not correct, so I need some help to make crack effect’s angle correctly.

(Sorry for the bad quality video.)

This is Raycasting script:

local Raycast = RaycastParams.new();
Raycast.FilterType = Enum.RaycastFilterType.Whitelist;
Raycast.FilterDescendantsInstances = {workspace.Map};

local ray = workspace:Raycast(LightningOrb.Position, LightningOrb.CFrame.UpVector + Vector3.new(math.random(-100, 100), -100, math.random(-100, 100)), Raycast);

This is set CFrame script:

Crack.CFrame = CFrame.lookAt(ray.Position, ray.Position - ray.Normal);

I tried adding CFrame.Angles(), but still can’t fix

1 Like
Crack.CFrame = CFrame.lookAt(ray.Position, ray.Position - Vector3.zAxis, ray.Normal);
1 Like


How about it on a wedge? (sorry, I’m bad at vector or CFrame things)

1 Like

It should also work on wedges unless there is some kind of snapping elsewhere in your code.

2 Likes

Umm… it looks like another problem has appeared.

1 Like

Whats the normal of that surface?

2 Likes


Here!

1 Like

This is cheesy but try this:

if math.abs(ray.Normal.Z) ~= 1 then
	Crack.CFrame = CFrame.lookAt(ray.Position, ray.Position - Vector3.zAxis, ray.Normal);
else
	Crack.CFrame = CFrame.lookAt(ray.Position, ray.Position - Vector3.xAxis, ray.Normal);
end

Clarification for future readers: This takes care of a special case of lookAt where if you look directly up or down relative to the up direction (third parameter) the chosen up direction effectively gets ignored. This is just the result of it not being possible to define a “look at” method that works in every direction consistently, there will always be two poles because you have to choose an up axis.

3 Likes

Thank you for the solution! This will assist me in better understanding some vectors.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.