tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 08:55 PM |
Kay... I made another thread about this earlier, but I didn't get any useful responses... so I'm gonna make a new thread in greater detail! (call me a spammer or whatever, I don't care...)
okay... I'm making an infinitely generating map. I need a way where it will spawn a model (called "Chunk" in the coding) at a certain position... the only way to achieve the most accurate position is to have it check the position of the nearest Chunk model, then go off of that... Question is, how do I make a script that checks the x, y, and z positions of the nearest model named "Chunk"? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Sep 2013 08:56 PM |
Not sure if this is what you want: Model:GetModelCFrame().
Also, bump your old thread next time. |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 08:58 PM |
| Will that cause the game to find the nearest model, named chunk ( at least 50 other models named this) then return the x, y, and z coordinates? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 08:59 PM |
| from the script's parent's current position in the workspace |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Sep 2013 09:01 PM |
Just do:
local ClosestModel = nil local ClosestPosition = 10000 for Index, Model in next, Game.Workspace:GetChildren() do if Model:IsA("Model") then (script.Parent.Position - Model:GetModelCFrame().p).Magnitude <= Blah and (script.Parent.Position - Model:GetModelCFrame().p).Magnitude < ClosestPosition then ClosestModel = Model ClosestPosition = (script.Parent.Position - Model:GetModelCFrame().p).Magniatude
It will require editing and end's |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 09:09 PM |
| Uhh... not exactly sure how this script works... Could you explain what "IsA" means? I'm not asking you for a step-by-step tutorial on how this script works... but I would like to know things like what the placeholders such as "blah" are placeholding... |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Sep 2013 09:10 PM |
| http://wiki.roblox.com/index.php/API:Instance/IsA |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 09:14 PM |
| oh man... I wish I knew about these things earlier... thanks! but still... which "model" placeholders do I replace with chunk and what is "blah" Place-holding? Sorry if I'm being annoying... I just can't wrap my head around this. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 09:21 PM |
| Oh, and yea, the script says that line 5 has an error... if you mouse over it, it says " "="expected near "<=" " |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 09:25 PM |
mmkay, thanks... But now which variable do I use to represent the position?
Example:
script.Parent:TranslateBy(Vector3.new( VARIABLE.X, VARIABLE.Y, VARIABLE.Z )) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Sep 2013 09:26 PM |
Why not just :MoveTo? But it would be that x, same with z (make a new variable just like x, but with z things). |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 09:28 PM |
| MoveTo Doesn't ignore hitboxes, which is critical for stuff like this. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Sep 2013 09:29 PM |
| Then yeah, use TranslateBy |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 09:30 PM |
| But whadda mean by "But it would be that x, same with z (make a new variable just like x, but with z things)." I don't see the script refer to any specific axis... |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Sep 2013 09:32 PM |
I got confused, I meant x/z being the closestmodel's position minus the current model's position (to get the offset) |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 09:36 PM |
Okay... I know your trying your best, and I'm being a clueless dork who's just making it harder, but lets take a look at the placeholder code to try to take a different approach...
PlayerX = game.Workspace.Player1.Torso.Position.X PlayerZ = game.Workspace.Player1.Torso.Position.Z
while true do wait(0.1)
if game.Workspace.Player1.Torso.Position.Y <= 6.3 then
print 'Generating land in Player Position....' a = game.Workspace.Chunk:clone() a.Parent = Workspace a:TranslateBy(Vector3.new(PlayerX/4, 6.3, PlayerZ/4)) print 'Generation complete' wait(5) end end
That code checks if the player jumps off the map, then generates a piece of land below him. The problem is that the chunk's position doesn't line up with the other chunks, so I need a script that checks the nearest chunks, then lines up the original model with the other chunks... all from the workspace.... |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 19 Sep 2013 09:39 PM |
| uhh... I think I've had enough late-night brain-frying for tonight... cya tomorrow... |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2013 10:13 PM |
| magnitude; getModelCFrame() |
|
|
| Report Abuse |
|
|
|
| 19 Sep 2013 10:26 PM |
function NearestModel(Name, Object) local p = Object:IsA("BasePart") and p.Position.magnitude or p:GetModelCFrame().p.magnitude local near,model; local function Scan(Parent) for Index, Child in pairs(Parent:GetChildren()) do if Child:IsA("Model") and Child.Name == Name then local dis=Child:GetModelCFrame().p.magnitude near = near and dis < near and dis or not near and dis or near model = near==dis and Child or model end Scan(Child) end end Scan(Workspace) return model.CFrame.p, model end
that might work, to use it:
local Position, Model = NearestModel("Chunk", script.Parent)
|
|
|
| Report Abuse |
|
|
|
| 19 Sep 2013 10:27 PM |
function NearestModel(Name, Object) local p = Object:IsA("BasePart") and p.Position.magnitude or p:GetModelCFrame().p.magnitude local near,model; local function Scan(Parent) for Index, Child in pairs(Parent:GetChildren()) do if Child:IsA("Model") and Child.Name == Name then local dis=(Child:GetModelCFrame().p-p).magnitude near = near and dis < near and dis or not near and dis or near model = near==dis and Child or model end Scan(Child) end end Scan(Workspace) return model.CFrame.p, model end
|
|
|
| Report Abuse |
|
|