generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Moving a model ontop of a part?

Previous Thread :: Next Thread 
TroubleDOG0100 is not online. TroubleDOG0100
Joined: 16 Sep 2014
Total Posts: 171
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 is not online. 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 is not online. 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 is not online. 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
TroubleDOG0100 is not online. TroubleDOG0100
Joined: 16 Sep 2014
Total Posts: 171
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image