Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I merge those two lines? CFrame question

Asked by 2 years ago
Edited 2 years ago

Hello, I've made a wall part to always be in front of the player when part of a script runs, this was working properly. However, as you can see in the code below, this merely makes the part go in front of the player ignoring if there is anything there, so it can float (due to being anchored).

SummonedEarthWall.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0, -3.5, -7)

I decided to use raycasting to fix the issue, making an invisible part to be placed where the wall would be instead, from then I cast a ray downwards to check if there is a floor and only if there is I'll allow the wall to be created there, above the floor. In order to do that I got this bit of code from a DevForum question which would help me with that.

SummonedEarthWall.CFrame = RayCastResult.Instance.CFrame * CFrame.new(0, RayCastResult.Instance.Size.Y / 2 + SummonedEarthWall.Size.Y / 2, 0)

This allows my part to be positioned just above the floor part no matter their size, but I'm not quite sure how I could merge those two lines of code in order to make the part be both above the floor which is the RayCastResult.Instance and still be in front of the player considering I have to change the Wall's CFrame to do each thing, and just multiplying all the CFrames like this:

(Character.HumanoidRootPart.CFrame * CFrame.new(0, -3.5, -7) * RayCastResult.Instance.CFrame * CFrame.new(0, RayCastResult.Instance.Size.Y / 2 + SummonedEarthWall.Size.Y / 2, 0))

It doesn't seem to work properly and I doubt that's how I should do that, for the reference the part's size is 8, 1, 2. I'm sorry if this is a dumb question.

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
2 years ago

You can use RaycastResult.Position which is the Vector3 point which the ray hit:

(Character.HumanoidRootPart.CFrame * CFrame.new(0, RaycastResult.Position.Y - 3.5 + SummonedEarthWall.Size.Y / 2, -7))
Ad

Answer this question