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 » Scripting Helpers
Home Search
 

Re: Aligning Part Faces

Previous Thread :: Next Thread 
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 05:16 PM
My goal is to align two faces from separate parts.

Before: http://prntscr.com/3mw7wn
After: http://prntscr.com/3mw7y5

Aside from the default Vector3 and CFrame properties, methods, constructors, etc, I have already created some functions that will be of use:

invertFace(face)
-face is of type Enum.NormalId; returns opposite face - type Enum.NormalId

getAxisFromFace(object, face)
-object is any basepart; face is any Enum.NormalId; returns axis face resides on(type Enum.Axis)

getPositiveFace(face)
-face is of type Enum.NormalId; returns a positive face so that Vector3.FromNormalId never contains negative numbers

getFacePosition(object, face)
-parameters same as getAxisFromFace; returns the position(x,y, and z) or the face

Given partA is being scaled and faceA belongs to partA, and partB is the reference and faceB is the targeted face of partB, how would I resize any given face to another on the same axis?

Issue you may run into:
getAxisFromFace does not function properly if the object is rotated

Quick links:
http://wiki.roblox.com/index.php?title=Vector3
http://wiki.roblox.com/index.php?title=CFrame

Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 05:18 PM
returns the position(x,y, and z) of the face*
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 05:35 PM
Here's what I have so far: http://www.roblox.com/Face-Aligner-item?id=158702025

Figured making it public would help others understand what I was trying to accomplish.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 05:37 PM
You want to resize it or move it, the pictures make me confused
Report Abuse
lupine is not online. lupine
Joined: 24 Jun 2008
Total Posts: 3561
26 May 2014 05:38 PM
face = part.CFrame*CFrame.new(0,0,part.Size.Z/2) -- or x or y along with any combination of positive/negatives.

That should work regardless of orientation, I think.
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 05:38 PM
Resize it. If you look at the first picture, you'll notice that the block on the right is smaller than the block on the left. If you take a glance at the second picture, they're both the same size.
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 05:41 PM
"face = part.CFrame*CFrame.new(0,0,part.Size.Z/2)"

I don't believe attempting to set a face equal to a CFrame is going to be a good idea.

"Hey, right, you're now CFrame.new(0,0,2)!"
Report Abuse
lupine is not online. lupine
Joined: 24 Jun 2008
Total Posts: 3561
26 May 2014 05:44 PM
Well, no
That's not setting the position of the side, it's telling you what the position of it.

x = Instance.new("Part", workspace)
x.Size,x.Position,x.Rotation = Vector3.new(0,0,0),Vector3.new(4,4,4),Vector3.new(45,45,45)
local topface = x.CFrame*CFrame.new(0,x.Size.Z/2,0)

'topface' should equal the midpoint of the top face. With that, you could more than certainly resize these parts together easier.
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 05:51 PM
"getFacePosition(object, face)
-parameters same as getAxisFromFace; returns the position(x,y, and z) or the face"

Already done.
Report Abuse
lupine is not online. lupine
Joined: 24 Jun 2008
Total Posts: 3561
26 May 2014 05:51 PM
"getAxisFromFace does not function properly if the object is rotated"
Sorry for being vague; I was posting a solution to this.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 05:52 PM
Not sure if this will work since I'm doing all of this without testing.

local partA = workspace.PartA;
local partB = workspace.PartB;

partB.Size = partA.Size;
partB.CFrame = partA.CFrame;
partB.CFrame = partB.CFrame * CFrame.new(-partA.Size.X/2, 0, 0);

This should set the size of PartB equal to that of PartA, then set the CFrame of PartB the same as PartA, then make it go to the relative left of partA
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 05:54 PM
@cnt: "partB.Size = partA.Size;"

partA is the one being scaled -- partB is the reference.

Also, I'm not looking to make them the same size -- sorry if I wasn't very clear. I'm looking to align faces.
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 05:57 PM
Here is another picture: http://prntscr.com/3mwqvx

The face with the hinge on the part to the left is being aligned to the face closest to the camera on the part to the right.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 06:02 PM
Oh, will you always know what axis it will have to be "stretched" on?
Report Abuse
sonicdiablo is not online. sonicdiablo
Joined: 05 Feb 2009
Total Posts: 1661
26 May 2014 06:05 PM
What about the case where the two faces can't be alligned?i.e when the two faces don't have the same rotation.
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 06:13 PM
'Oh, will you always know what axis it will have to be "stretched" on?"

Yes:
"getAxisFromFace(object, face)
-object is any basepart; face is any Enum.NormalId; returns axis face resides on(type Enum.Axis)"

"What about the case where the two faces can't be alligned?i.e when the two faces don't have the same rotation."
I do a check beforehand to make sure both faces are on the same axis. All aligning does is moves one face's position to the target face's position and resizes the first object accordingly. Say my first face is on the X axis, but my second is on the Y. The first will just align to the X position of the second's face instead of the Y.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 06:17 PM
In that case, why not just do something like:

local sizeOfAxisDiff = scaled.Position.axis - part.Position.axis
local partPos = part.Position
part.Size = part.Size + Vector3.new(0, sizeOfAxisDiff, 0)

Or something like that
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 06:18 PM
No in the y-component, but I didn't know what you were using so yeah.
And then after, just set part.Position to match up so it goes where it started
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 06:19 PM
Because it doesn't work for rotated objects :(

I've already gotten that far -- take a look at the model I liked. I believe I still have it in there, but commented out.
Report Abuse
flatline115 is not online. flatline115
Joined: 29 Jul 2013
Total Posts: 7826
26 May 2014 06:20 PM
1. Just get the CFrame of the part you want to align
2. Add or subtract that from the Size of your part on said axis.
3. ????????????????????????????????????????????????????
4. Profit.
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 06:24 PM
@flat: As stated previously, I already have a function for getting the face's position -- that is not an issue. The issue is how to align faceA to faceB.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 06:24 PM
So basically, you wan't faceA to point in the same direction faceB is pointing?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 06:27 PM
lol "wan't"
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 06:29 PM
faceA is already pointing in the direction as faceB.

Go here:
http://www.roblox.com/test-place?id=15835950

Pick any pair of parts. Click the button in the upper left corner, click the face with the hinge on it(the smaller brick), then click the face with the motor on it(The larger brick). That works -- that is what I'm trying to accomplish -- I have it working to that point; however, if the parts are rotated, it no longer works -- that is the problem.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
27 May 2014 06:02 AM
I don't see why you would ever really want to do this, but ok... First off, don't make a bunch of useless functions without knowing how to actually fix the problem. First find the solution through math, then split it up into functions if need be.

local A = workspace.A
local B = workspace.B

-- A is the main part, B is the part that is changing. If you have a problem with that, take it up with someone else

local n = Vector3.new(0, 0, -1)

-- n is the normal of the face of the B part that you want to scale up (in object space)

local wn = B.CFrame:vectorToWorldSpace(n)

local Ap = A.CFrame * (A.Size/2 * A.CFrame:toObjectSpace(B.CFrame):vectorToWorldSpace(n))
local Bp = B.CFrame * (B.Size/2 * n)

local t = wn:Dot(Ap - Bp)

-- then you just add t to the size in the direction of the normal, and translate by t/2 in the direction of the normal

local s = B.Size + Vector3.new(math.abs(n.x), math.abs(n.y), math.abs(n.z))*t
local c = B.CFrame + wn*(t/2)

B.Size = s
B.CFrame = c

Btw, this doesn't require you to select two faces. It will automatically use the proper face. I've tested it, and it seems to work for all cases. That is, as long as the normal is a proper normal in object space, and the parts are perpendicular.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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