Help making mesh look at other mesh!

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make an arrow mesh point at a glasses mesh so the player knows where to go.
  2. What is the issue? Include screenshots / videos if possible!
    The script doesn’t work for some reason.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried using parts and it works but not for meshes for some reason?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

arrow2.CFrame = CFrame.lookAt(arrow2.Position, glasses.Position)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Try using CFrame.new instead.

I’ve tried that but it didnt work aswell.

Maybe the mesh has its own rotation that does not look toward the -Z direction (forward). You should set the mesh to look forward then multiply that CFrame with the CFrame.lookAt().

local meshRotation = arrow2.CFrame - arrow2.CFrame.p -- This should be stored somewhere as a constant
arrow2.CFrame = CFrame.lookAt(arrow2.Position, glasses.Position) * meshRotation

You should probably store the CFrame rotation somewhere if you’re going to use it often though.

What do you mean by it “doesn’t work”? Does it not work at all and errors or does it not work like you want it to? A screenshot would help

no errors in output and the arrow doesnt face the direction of glasses

I will try that right now and get back to you.

it didn’t work and there are no errors in output.

If you upload a place file with the arrow and glass, then I could show you what I meant. I’ll try to get an example then.

I did everything you said. Also I cant upload the place because it is a group project and I’d have to ask owner if I could just for privacy.

Here is what I mean. Notice how the bullet is facing forward and has a rotation. You can tell that the mesh is looking forward when moving it left will change the first number in its position by negatives and moving it right will increase the first number (ex left: Vector3.new(-1, 0, 0), right: Vector3.new(1, 0, 0)).

Bullet.rbxl (59.0 KB)

Actually you can just use the “Build Rig” plugin in the plugins bar. The characters in there will always face forward.

I did what you did in the script and it didn’t work for some reason. In the script I have the original mesh in replicated storage but then I clone it and name the variable arrow2 is that why the lookat isn’t working?

You need to make the rotation a constant aka not changing. Save the rotation of the bullet at the top of the script, when it’s created, or something. Then use that constant in your CFrame.lookAt calculations.

Notice how in my demonstration, the rotation is at the very top of the Server Script and does not change.

Is the code in the same script that clone a mesh?

yes and also the arrow2 is welded to the players head.

I made a special mesh and a meshpart and a target part stored in a replicatedstorage
Each blocks will loop and face to each position of the target, code:
local thing = game.ReplicatedStorage.Target:Clone()

while wait() do

thing.Parent = game.Workspace

script.Parent.CFrame = CFrame.lookAt(script.Parent.Position,thing.Position)

end

The results It return pretty what I want
My conclusion is that the script is already correct but the mesh has it’s problem, to fix it, make a decal and make a face to the front. If the decal lands on a direction you want. That means the script might just have it’s mistake. But If it’s wasnt. That means you should do a new mesh

the arrow had decal on front but the front side didnt face the direction of glasses and the script isn’t wrong and I tried another mesh but same problem maybe its the weld?

Can I see the arrows properties? Since you might be setting a wrong cframe

1 Like

So from what I’ve noticed so far from all the replies is that you’re working with welds, correct?

CFrame on baseparts (Meshpart, part, etc) do not work if they are welded to an object.

If you want the arrow to indicate towards a position you might either have to get rid of the weld itself, or use a bodyposition+bodygyro combination.

Edit: could also manipulate the C0/C1 of the welds, your pick.

2 Likes