I would like to create a part between two Vector3 positions. I using this to create some kind of gun, and I didn’t want the laser to go through wall, so I am taking the position of the barrel and the position of where the ray hit and combining them. This is what I have so far:
local function addVectors (Vect1, Vect2)
return (((Vect1.X + Vect2.X)/2) + ((Vect1.Y + Vect2.Y)/2) + ((Vect1.Z + Vect2.Z)/2)) / 3
end
local laserPart = Instance.new("Part", workspace)
laserPart.Name = "Laser"
laserPart.Anchored = true
laserPart.CanCollide = false
laserPart.CFrame = CFrame.new((Tool.Handle.Barrel.WorldPosition + showRay.Position) / 2, Tool.Handle.Barrel.WorldPosition)
laserPart.Size = Vector3.new(0.1, 0.1, addVectors(Tool.Handle.Barrel.WorldPosition, showRay.Position))
laserPart.Material = Enum.Material.Neon
laserPart.BrickColor = BrickColor.new("Bright green")
The main problem I am having is finding how to accuratly make the size of the part correct. I have tried various methods on what to do, but none have worked. Thank you to everyone in advance!
What methods have you tried so far?
I have tried adding each of the values of each axis together and divided it mostly.
Have you tried (Vector3 - Vector3).magnitude ?
4 Likes
Sounds like a good idea, I completely forgot about .magnitude
.
Styre_x
(Styrex)
August 28, 2020, 7:12pm
#6
This question has been asked on many sites before.
Lets say I have to Vector3's: Vector3.new(-10, 0, 0), and Vector3.new(10, 0, 0). How would I position a part in between those to positions? Like I could simply just position them at Vector3(0, 0, 0) (Which would directly in between them, and would be correct), but the positions could be different every time. I remember a topic like this a while back, but I could not find it, so thats why I am posting a topic on this.
How would I go about forming a part using a script which connects two points together? Is there a roblox event for this? The two points have completely different x, y and a values. No x, y or z value are the same. My current problem would be how to orientate the part to connect between the two points.
Please search before you ask a question
Here is code to make a part go between two points:
local Distance = (p0-p1).Magnitude
Part.CFrame = CFrame.new(p0,p1) * CFrame.new(0,0,-Distance/2)
Part.Size = Vector3.new(1,1,Distance)
6 Likes
Okay, thank you. Sorry for reposting, I couldn’t find a good reference…
1 Like
part.CFrame = part1.CFrame:Lerp(part2.CFrame, .5)
I think its like this
1 Like