How to place a part infront of character while keeping its orientation relative to the character?

This slash ends up being based on the world axis only and it’s rotated backward for some reason

Could you show an image of how you’d want the slash to face? From what I gather, you want to keep the rotation but relative to the torso’s direction, which I imagine something like this would work instead:

local rotation = Slash.CFrame - Slash.Position
Slash.CFrame = torso.CFrame * CFrame.new(0, 0, -10) * rotation

If that’s constantly facing the wrong direction, then just multiply the CFrame by some constant angle - for example, multiply by CFrame.Angles(math.pi / 2, 0, 0) or by CFrame.Angles(0, math.pi / 2, 0).

local direction = Slash.CFrame - Slash.CFrame.Position
local offset = torso.CFrame.Position + torso.CFrame.LookVector * 10
	
local cf = direction + offset
	
Slash.CFrame = cf

This gives the solution of being relative to the torso, but it is flipped like you mentioned, :sweat_smile:

Here’s a demonstration of how the slash is supposed to face, apologies for not showing one initially

  • *The red arrow is just an aid to show the direction of the slash
  • The first row is the intended orientation, where the slash faces forward relative to the character’s direction.
  • The second row is the result of many solutions given in this thread, where it’s relative to the world axis and not the character’s direction, the result of
local rotation = Slash.CFrame - Slash.Position
--
Slash.CFrame = CFrame.new(torso.Position + torso.CFrame.LookVector * 10) * rotation
--or 
Slash.Position = CFrame.new(torso.Position + torso.LookVector * 10).Position
--or
local offset = torso.CFrame.Position + torso.CFrame.LookVector * 10 	
Swallow.CFrame = rotation + offset
  • The third row is the solution you gave, which is relative to the torso, but the slash is flipped, the result of:
local rotation = Slash.CFrame - Slash.Position
Slash.CFrame = torso.CFrame * CFrame.new(0, 0, -10) * rotation

This also only faces forward on the world axis unfortunately

I think:

local offset = 10 -- studs
slash.CFrame = CFrame.lookAt(root.Position, root.Position + (root.CFrame.LookVector * offset))

Didn’t work either, it’s not properly oriented either in the air

And just for references, the part is being pulled from replicated storage, parented in workspace, and then CFrame adjusted by your guys’ recommendations.

I was thinking of just turning it into a model but that’s probably not going to work well either, at this point Im ready to just give up

Can you send a picture of whats happening when you use my code? I used this for spawning vehicles in front of the player today, no reason it doesnt work.

image
Essentially like so
Maybe this is because it’s a union part? I have no idea.

Whats the pivot point of your mesh? Select it in studio and send a picture
You could try offsetting the cframe.

local offset = 10 -- studs
slash.CFrame = CFrame.lookAt(root.Position, root.Position + (root.CFrame.LookVector * offset)) * CFrame.Angles(-90, 0, 0)

Try this:

local dir = Slash.CFrame - Slash.CFrame.Position
local real_dir = torso.CFrame * dir

real_dir = real_dir - real_dir.Position

local pos = torso.CFrame.Position + torso.CFrame:VectorToWorldSpace(Vector3.new(0, 0, -10))
Slash.CFrame = real_dir + pos

Cant you just use lookvector for dir?

Using LookVector for dir won’t give the result that OP wants.

The pivot and pivot offset’s are 0,0,0
image

Orientation values from Rep Storage before it gets cloned
image

Orientation values in game/workspace during test mode:
image

Offsetting the CFrame could work but even when I tried to copy and paste the values from Rep Storage into the script, it still came out weird. So it would have to be manual trial and error which I wanted to avoid

Im 100% sure op just has to mess with the mesh pivot point though.

Place it in workspace and not in rep for a moment and send a pic (while in studio). It must be the pivot.

I meant that I was copying from Rep Storage and pasting into workspace* (ctrl + C → ctrl + V)

When doing that, it places properly with the same orientation it has in Rep Storage
image
image

Though using your method, this is what it ends up looking like with different orientation in test-mode when copying and pasting with the script
image

image

So, I’m not sure exactly where both your character and slash part are facing, so I’ll tell you how to get the angles so that the slash faces the direction you want it to.

First, get your slash part into workspace and face the dummy towards it.
Then, go into the command bar and input the following code - just set your respective paths for the dummy and slash variables:

local dummy = -- path to the dummy
local slash = -- path to the slash in workspace
local rotTransform = (slash.CFrame - slash.Position) * (dummy.Torso.CFrame - dummy.Torso.Position):Inverse()
print(rotTransform)

What you should get in the output is a set of numbers. You’ll want to copy these numbers to paste into your script. Put them inside of a CFrame.new() as variable, like this:

local rotation = CFrame.new(...)

If you’re using the code I sent before, that’s all you have to do. Here’s the new code regardless (which instead of ..., you’d have the numbers from the output):

local rotation = CFrame.new(...)
Slash.CFrame = torso.CFrame * CFrame.new(0, 0, -10) * rotation

Is there a nicer way to do this? Yes, I’m sure there is - personally I’d do something along the lines of storing the orientation values of the slash relative to the torso whose orientation is 0, 0, 0 (which is basically what I did for you here, but without me knowing exactly how your slash and characters are set up).

all you have to do is use ToWorldSpace.