Part just disappearing when rotating it?

Hey, so I am getting the lookvector of one part and i use the dot product on the direction between the position of both, and I get the angle using the arc cosine, but when I try actually rotating it, i dont even know it just like is being super dumb

Video

My code


No idea how to use :Dot or math.acos, but just changing the orientation should definitely not change the position. Try printing what the angles translation is? Maybe it has something to do with a translation every heartbeat.

What are you trying to accomplish?

Yeah I print out the angle and it is the right angle

The dot product is basically is a scalar which returns a number from -1 to 1 depending on the relation of the direction of the two vectors

All I am trying to do is simply rotate the blue part to face the green part

Can’t you just use CFrames only look make it look at the part?

local blue, green -- fill in the variable
blue.CFrame = CFrame.new(blue.Position, green.Position)
-- use below if you need to make a different face point to green
blue.CFrame *= CFrame.Angles(0,math.rad(90),0)

Yes that works but I dont want to make it that easy for myself, I want to do it my way using acos and the dot product.

No, the dot product only does that if both the inputs are length 1. The dot product can be any positive or negative value if the lengths are not 1.

1 Like

Yeah I forgot the its only useful when the vectors are normalized mb

Why are you making it harder on yourself? I’m confused.

I’m not making it harder for myself, I am trying to learn and expand my knowledge and I need to have a full understand of the basics

this cant be hat hard so can someone please help me solve this the way I intend?

What’s happening is, similar to your other question, you’re going outside the range for which acos() is defined, which results in you passing a NaN to Angles, which will send your part to the shadow realm if the resulting CFrame is used to position or even rotate the part. Try printing the angle and you will probably see “NaN” once the part disappears.

1 Like

Okay but how can I fix it, I need the HOW

edit: you were right it does say nan
image

 --You MUST have this check, the Unit vector of zero is NOT DEFINED
if (p2.Position - p1.Position) == Vector3.zero then
	return
end

local direction = (p2.Position - p1.Position).Unit
--Rest of your code

This is my updated code and it’s just going crazy now and not even facing it correctly


Try removing the use of both math.deg and math.rad, because math.acos probably returns in radians. (don’t yell at me idk how acos works)

The stuttering might have something to do with how parts are dragged, so you should debug with TweenService by making the part move like that, to see how the blue part looks at it.

That cant be it because when i use math.deg I converted it into degrees and math.rad takes degrees
image

Well yes. It converts the radians to degrees, and then back to radians. Maybe some math impresions are causing the stuttering.

Alright I tried it, still giving the same hiccuping and not facing the right direction :upside_down_face:

By the way, arccos returns a value between (0, 2pi] when given a number between -1 and 1. it’s just the opposite of cosine.