|
| 03 Sep 2017 10:16 AM |
So i am experimenting with a furniture placing system, i got a version working. But that version has got quite a lot of if statements which i don't like. So what's the most efficient way to put a model ontop of a part and to have the same rotation as the part, and also for the player to be able to move it across different axes using the mouse?
LookVector? or something else?
Please any advice would be very nice, if more info is needed i would be happy to reply.
Thanks Trouble!
|
|
|
| Report Abuse |
|
|
samy22
|
  |
| Joined: 28 Sep 2008 |
| Total Posts: 2181 |
|
|
| 03 Sep 2017 10:26 AM |
The most efficient way I can think of to do that;
Compare the angle between Vector3.new(0,1,0) & each of the following; rightVector, upVector and lookVector and their negative versions until you find the smallest angle produced by one of the 6 vectors.
Then, move your object by that vector across until your object barely touches the part you took Vectors' from. |
|
|
| Report Abuse |
|
|
samy22
|
  |
| Joined: 28 Sep 2008 |
| Total Posts: 2181 |
|
|
| 03 Sep 2017 10:43 AM |
function AngleBetweenTwoUnitVectors(v1, v2) return math.acos(v1:Dot(v2)) end
function findVectorPointingTheHighest(Part) local a = {} local v = {Vector3.new(1,0,0), Vector3.new(0,1,0), Vector3.new(0,0,1)}
for i = 1, 6 do local bool = i>3 and -1 or 1 local currentv = Part.CFrame:vectorToWorldSpace(v[(i-1)%3+1]*bool).Unit --Unit probably not needed a[i] = {currentv, AngleBetweenTwoUnitVectors(currentv, Vector3.new(0,1,0))} end
table.sort(a, function (l,h) return l[2] < h[2] end)
return a[1][1] end
|
|
|
| Report Abuse |
|
|
samy22
|
  |
| Joined: 28 Sep 2008 |
| Total Posts: 2181 |
|
|
| 03 Sep 2017 10:45 AM |
Or...
just use .Position which automatically puts an Object ontop of another Object if they intersect. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2017 10:51 AM |
| Well thanks for the help, gonna try to do that thing u first said cuz, i don't think the .position think will work if i wanna make the model on a side of a wall, it's only gonna work for floors. |
|
|
| Report Abuse |
|
|
samy22
|
  |
| Joined: 28 Sep 2008 |
| Total Posts: 2181 |
|
|
| 03 Sep 2017 11:21 AM |
Oh, if by "on top" you meant, in front... and for it to work similar to the roblox placement system in studio.
You could cast a ray from your camera Position to mouse.hit.p and use FindPartOnRay to return the first intersecting part on that line/ray which will return it's surface normal.
Then you simply translate by that surface normal vector until your object being dragged barely touches the surface. |
|
|
| Report Abuse |
|
|