So I want a way of making a part orientate according to the terrain angles and stuff like this
But I have no clue how to do this or code such a thing
This comes from this post here:
if you guys could help me it would be nice
So I want a way of making a part orientate according to the terrain angles and stuff like this
But I have no clue how to do this or code such a thing
This comes from this post here:
if you guys could help me it would be nice
Wherever your target position for your sidewalk is, you’ll need to raycast downwards and get RaycastResult.Normal
and RaycastResult.Position
. Use the normal as an up vector for your sidewalk part’s CFrame. If you already know which direction your sidewalk should face in, you can use that as your forward vector. From there, you can construct a CFrame using the following:
local sidewalkPos = -- position your raycast hit
local upVec = -- whatever the normal is of your raycast
local forwardVec = -- whatever direction your sidewalk should face in
local rightVec = forwardVec:Cross(upVec)
local sidewalkCf = CFrame.fromMatrix(sidewalkPos, rightVec, upVec, forwardVec)
I may have gotten the forwardVec:Cross(upVec)
backwards. If your sidewalk faces upside down when you get this working, swap the 2 vectors.
Hmm, if you look closely at the path there are square parts along the path.
I’m assuming that these square parts are used to generate the path and connect the rectangular path together.
I also know that you can generate these two points by drawing the blue line in the diagram below which is normal to a bezier curve to get two points in which you can make a red path.
Perhaps you can project this 2d drawing onto the 3d terrain by raycasting from above to put these parts onto the terrain. Like what @EncodedLua suggested.
These are just ideas to help you get started to attempt to form a solution on your own. Feel free to ask more questions
What do you mean normal of my ray?
This is what I have so far
local RayNew = Ray.new(Part.Position + Vector3.new(0, 10, 0), Vector3.new(0, -100, 0))
local Hit, Position = workspace:FindPartOnRay(RayNew)
local sidewalkPos = Position
local upVec = Part.Orientation
local forwardVec = Part.Orientation
local rightVec = forwardVec:Cross(upVec)
local sidewalkCf = CFrame.fromMatrix(sidewalkPos, rightVec, upVec, forwardVec)
local Part3 = Instance.new("Part")
Part3.CFrame =sidewalkCf
Part3.Anchored = true
Part3.Parent = workspace
The “normal” means the vector that describes the direction the surface hit by the ray faces. So if you raycast downwards and it hits a flat part, the normal returned would be (0, 1, 0)
.
I still dont understand though all the equation is doing for me now is just placing parts above the trrain without any orientation
And also it does not hit terrain
This is waht I have got but it is not working
local RayNew = Ray.new(workspace.Part.Position, Vector3.new(0, -250, 0))
local Part, Position, SurfaceNormal, Material = workspace:FindPartOnRay(RayNew)
print(Part, Position, SurfaceNormal, Material)
local sidewalkPos = Position-- position your raycast hit
local upVec = SurfaceNormal-- whatever the normal is of your raycast
local forwardVec = Position-- whatever direction your sidewalk should face in
local rightVec = forwardVec:Cross(upVec)
local sidewalkCf = CFrame.fromMatrix(sidewalkPos, rightVec, upVec, forwardVec)
local Part = Instance.new("Part")
Part.CFrame = sidewalkCf
Part.Anchored = true
Part.Parent = workspace
Its I think just on the
local forwardVec = -- whatever direction your sidewalk should face in
I dont know how to do
It’s just a vector that should represent the direction your part should face, so if you have a building system where you click to place something, you can get the look vector of the preview part’s CFrame.
Well Is it just like Part.Orientatrion because that does not wokr the y value goes to - 234543536543
still needing help with this btw
Well, this worked perfectly, thank you.