How to use CFrame.lookAt()

I’m not quite sure what you mean, do you mean have the arrow face the camera while still pointing at an object?

Im pretty sure he means not making the arrow tilt, cause the arrow seems to be tilting a bit

This is what it looks like now

Technically the arrow is pointing at SpawnLocation, but the engine doesn’t know that I want the arrow’s guide to point at SpawnLocation

And that’s what I want to achieve

image

So that the arrow is always directed to SpawnLocation relative to its structure.

I think that’s just your union, when you union parts together the union’s orientation is based off the first part you selected. So make a new union by selecting the long part of the arrow first, and make sure it’s LookVector face is in the direction of the arrow.

1 Like

Try adding a part in the position of the arrow, group and weld the arrow to the new part and set the primarypart to the new part, then rotate the arrow to face the front side of the the new part.

Then rotate the CFrame of the grouped arrow’s primary part to face what ever direction you want it to face

1 Like

So UpVector will not help in this situation?

Then how to work with UpVector? I don’t quite understand what you meant here.

arrowLookAt.rbxl (59.2 KB)
Here’s a working demo place. The arrow points towards a target part while also facing the camera. Script is under StarterPlayerScripts.

1 Like

To my knowledge, the upVector would help with your solution, but would require you to guess the rotation in which the arrow would correctly be rotated. And well, I’d probably not try and guess what the correct vector would be.

1 Like
local up = (lookAt - at).Unit:Cross((camera.CFrame.Position - at).Unit)

Yes, you did what I wanted, but could you explain how this part works?

First you find the direction of both vectors and get them into 1 stud using Unit, then use Cross to find the perpendicular angle relative to the camera direction and “at”. But why are you doing this?

Please explain each step, it will help a lot!

The only reason my arrow faces the correct way as opposed to yours is I unioned it correctly so the ‘front’ face of the arrow is the direction it’s pointing.

The up in the code only makes it so the arrow also faces the camera, if you removed it the arrow will still point towards the target, it just won’t always face the camera. As for how I came up with that equation… I trial and errored it until it worked haha. Sorry I don’t have much of an explanation.

1 Like

That is, you calculated all this during the time we were discussing? This is strong! Thank you, you really helped a lot.

What special things did you do to make everything work as it should? I read your answer above, separated, turned in all directions, but nothing happened. :smiling_face_with_tear:

it’s just a weird thing about unioning. When unioning, the first part selected dictates what the union’s orientation is. In the image below, the green arrow represents the union’s front face based on what part you select first. Left is how I unioned mine, right is how I think yours was unioned and hence your rotation being off.

Also, if your issue is resolved please mark the post as solved.

1 Like

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