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
 

Re: Making a saw mill

Previous Thread :: Next Thread 
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
02 Feb 2017 06:08 PM
So I want to cut the log by the direction it hits the saw.
Sounds pretty easy, but after you take longer than 20 seconds to think of it, it becomes mind boggling.


I have absalutley no idea how Im going to accomplish this, however heres some things to make it easy.


Theres only three axis to cut from, and basicly whatever side of the part hits the saw first, gets cut in half. (Direction of the saw does not matter)
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
02 Feb 2017 06:09 PM
can you only cut the logs in half too? or can you slice them by different thicknesses
Report Abuse
JasonXunn is online. JasonXunn
Joined: 18 Jan 2015
Total Posts: 857
02 Feb 2017 06:10 PM
(Insert brain blowing up here)
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
02 Feb 2017 06:10 PM
I would just cut them in half, otherwise using them to actually build something would become monulentaly harder.
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
02 Feb 2017 06:11 PM
I would probably compare the lookVector of the part to the direction the two positions make



local lookvector = log.CFrame.lookVector
local dir = (log.Position-saw.Position).Unit
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
02 Feb 2017 06:12 PM
I'd just look at the code for this.

https://www.roblox.com/library/143152131/Brick-Cutter-Plugin
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
02 Feb 2017 06:12 PM
^That code is completely diffrent.
Its using mouse clicks to slice them based on size.
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
02 Feb 2017 06:14 PM
what part of the saw mill are u having trouble with?
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Feb 2017 06:14 PM
I think joey is onto something. You can compare the cross vector using the lookVectors (0,0,1), (1,0,0), and the negative versions.
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
02 Feb 2017 06:15 PM
local lookvector = hit.CFrame.lookVector
local dir = (hit.Position-part.Position).Unit
print(lookvector-dir)

>
-0.0301316027, -1.05948555, 1.02030551


That code printed that, which is signifacant because the first one is 0 :O

Now what to do with it lol
Report Abuse
lijee1000 is not online. lijee1000
Joined: 26 May 2012
Total Posts: 14
02 Feb 2017 06:16 PM
BOOOM MIND BLEW UP -I am not good at coding
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
02 Feb 2017 06:25 PM
I came up with this however It doesnt work well. Not sure how to callibrate it ] local lookvector = hit.CFrame.lookVector local dir = (hit.Position-part.Position).Unit local diff = lookvector-dir local min = ############################## local max = math.max(diff.X,diff.Y,diff.Z) if min == diff.Y then print("Y") ######## # ######## * Vector3.new(.5,1,1) elseif min == diff.Z then print("Z") ######## # ######## * Vector3.new(1,.5,1) elseif ### ## ###### then print("X") ######## # ######## * Vector3.new(1,1,.5) end
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
02 Feb 2017 06:36 PM
Alright, I've got it really close however it doesn't quite work depending on where the log is rotated. For example if its rotated one way, but if you roate along the axis that (isnt) supposed to matter, it doesnt.. local lookvector = hit.CFrame.lookVector local dir = (hit.Position-part.Position).Unit local diff = lookvector-dir local # # ################ local Y = math.abs(diff.Y) local Z = math.abs(diff.Z) local min = math.min(X,Y,Z) print(X,Y,Z) if ### ## # then print("X") *cut X size in half) elseif min == Y then print("Y") *cut Y size in half* elseif min == Z then print("Z") *cut Z size in half* end
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
02 Feb 2017 06:37 PM
pastebin
N2iPKFKq
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
02 Feb 2017 06:43 PM
I can't compare it to the lookvector of the log because,

It worked well at rotation 0,0,0, but if I did 0,0,90, It had the same lookvector.
However it would cut well at 0,0,0, and not 0,0,90


So I asume I need two directions, upVector?
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Feb 2017 08:58 PM
pastebin
com/j0XDPpyj

Okay so,

a.Position - b.Position
^ This vector points a and b. CFrame.new(a.Position, (a.Position - b.Position).Unit)
Using the CFrame example I have just provided, you can see it indeed points at it. We want to keep this normalized.

The theory goes, the more the lookVector is rotated towards, the more towards 0 the dot product will come out to be. Anything greater than that means it probably isn't looking at it. In fact, it seems like -1 > 0 < 1 would be a visually acceptable range to allow as leniency room.

I take the right, left, and top vectors, which are already normalized directions, and dot them against the normalized toPosition variable, which is the direction to our goal.

--

So we got a plan on how to solve this out. From here it is just testing to see if you can create some logic to detect the side. An idea I have would to be floor it and not accept anything above 2 or less than -2 to agree if the side should be cut. Obviously if it is negative, it would be cutting from the opposite side, it shouldn't matter thereof.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Feb 2017 09:01 PM
Oh and I might want to add that you only need the X and Z 'normals' here. Even more specific, you only need the X or Z. With a bit of test you can determine acceptable ranges, but it would probably be easier to use both X and Z.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Feb 2017 09:04 PM

math.floor(-0.433) --> -1

Well... umm
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Feb 2017 09:23 PM
local floor = function(n)
return n < 0 and math.ceil(n) or math.floor(n)
end

local round = function(a, b)
b = b or 1
return floor(a*b + (0.5 * (a < 0 and -1 or 1)))/b
end


While trying to figure out whats up, it seems like only the lookVector and rightVector are necessary, and does make it easier as I suspected. I also had to make them round and my own floor. I needed it so that when -1 > n < 0, flooring would go to 0, not -1. The rounding is to take away floating point error and rid of the floating as it is unnecessary. That also led me to the results of the second paragraph below.

It seems like when output is 1, 1, the saw is cutting in a loose diagonal. When 1, 0, it is cutting more towards forward. When 0, 1, it is cutting more towards the right.

Which is excellent! However, I am thinking it is in order to reduce the midway leniency here - so that it could pref a side based on rotation. However, that might mean taking out round and replacing it with a system that rounds up to 0.5 intervals... Example, 0.2 would round to 0, 0.3 would round to 0.5... That seems a little disgusting.

The other option would to utilize it without the rounding. It would pref the |lookVector dot| that is greater.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Feb 2017 09:26 PM
pastebin
com/dKkLyg21

Hop skip and cheer, here is your problem fixed.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Feb 2017 11:24 PM

local log = workspace.Log
local saw = workspace.Saw

local split_part = function(p1, dir)
local p2 = p1:Clone()
p2.Name = "log2"

local p1c = p1.CFrame
local p2c = p2.CFrame

p1.Size = Vector3.new(dir and p1.Size.X/2 or 1, 1, not dir and p1.Size.Z/2 or 1)
p2.Size = p1.Size

p1.CFrame = p1c * CFrame.new(dir and -p1.Size.X/2 or 0, 0, not dir and -p1.Size.Z/2 or 0)
p2.CFrame = p1c * CFrame.new(dir and p1.Size.X/2 or 0, 0, not dir and p1.Size.Z/2 or 0)
p2.Parent = game.Workspace
end

local toPosition = (saw.Position - log.Position).Unit
local n1 = math.abs(log.CFrame.lookVector:Dot(toPosition))
local n2 = math.abs(log.CFrame.rightVector:Dot(toPosition))
print("look", n1, " ", "right", n2)

split_part(log, n1 > n2)

I even made a cute little test case for ya. Enjoy.

Log: game.Workspace.Log, Part, Position:0,0,0, Rotation:-180,-71.427,-180, Size:1,1,1
Saw: game.Workspace.Saw, Part, Position:0.03,-0.405,3.93, Rotation:0,0,0, Size:0.2,3.73,4.86
script: game.Workspace, script







Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
03 Feb 2017 09:22 PM
Wow that's amazing actually. I havn't test it yet but thanks for taking the time to do this!
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
05 Feb 2017 01:39 PM
Tested it and it wroks break in some cases but if the logs more than 1,1,lengh it fails
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