|
| 17 Apr 2016 12:55 PM |
Ok, so lets say I have a part in workspace named "block" and its size is 20 x 1 x 20 studs. let's say I have another part in workspace named "block2" and its size is 1 x 1 x 1 studs.
I will try to explain my question as best as I can...
How can I make a script that will change "block2"s position to any random spot on "block"s surface?
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2016 01:03 PM |
try something like
b1 = game.Workspace.block b2 = game.Workspace.block2
b2.Position = b1.Position + Vector3.new(math.random(1,b1.Size.X), b1.Position.Y + b1.Size.Y, math.random(1, b1.Size.Z))
--I have not tested this, but something like this should work. ---Hopefully this helped you.. |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2016 01:04 PM |
or if you want it to loop just add while true do
b1 = game.Workspace.block b2 = game.Workspace.block2
while true do b2.Position = b1.Position + Vector3.new(math.random(1,b1.Size.X), b1.Position.Y + b1.Size.Y, math.random(1, b1.Size.Z)) wait() end
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2016 01:09 PM |
almost there...
It sometimes works, but sometimes, b2's position is not on b1. I want b2 to always be on the surface of b1 |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Apr 2016 01:13 PM |
b1 = game.Workspace.block b2 = game.Workspace.block2
while true do b2.Position = b1.Position + Vector3.new(math.random(1,b1.Size.X), b1.Position.Y + (b1.Size.Y/2), math.random(1, b1.Size.Z)) wait() end
--This should work now. |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2016 01:15 PM |
No it should be like this: b1.Position.Y + (b1.Size.Y + b2.Size.Y)/2
If you only add half of b1.Size.Y, the center of b2 is on the surface of the part. You want to raise it by half of b2.Y to make the bottom of b2 on the surface of the part. |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2016 01:49 PM |
ASSUMING THAT B1 MIGHT BE ROTATED ARBITRARILY:
function pointOnFace(part, face) local faceVector = Vector3.FromNormalId(Enum.NormalId[tostring(face)]) local perpVector = Vector3.new(1, 1, 1) - faceVector perpVector = Vector3.new( perpVector.X * math.random(), perpVector.Y * math.random(), perpVector.Z * math.random() ) local horizontalPos = perpVector * part.Size - part.Size * 0.5 local finalPos = horizontalPos + part.Size * faceVector return part.CFrame * CFrame.new(finalPos) end
Instance.new("Part", game.Workspace).Anchored = true
while wait() do local p = game.Workspace.Part:Clone() p.Parent = game.Workspace p.CFrame = pointOnFace(game.Workspace.BasePlate, "Back") end
|
|
|
| Report Abuse |
|
|
|
| 17 Apr 2016 02:07 PM |
This is what I have, yet b2 is still not always on the surface of b1
local b1 = game.Workspace.block local b2 = game.Workspace.block2
while true do b2.Position = b1.Position + Vector3.new(math.random(1,b1.Size.X), b1.Position.Y + (b1.Size.Y + b2.Size.Y)/2, math.random(1, b1.Size.Z)) wait(1) end |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Apr 2016 02:59 PM |
| could someone please help me? |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2016 03:11 PM |
b2.Position = b1.Position + Vector3.new( math.random((-b1.Size.X + b2.Size.X)/2, (b1.Size.X - b2.Size.X)/2), b1.Position.Y + (b1.Size.Y + b2.Size.Y)/2, math.random((-b1.Size.Z + b2.Size.Z)/2, (b1.Size.Z - b2.Size.Z)/2), )
hopefully i didnt make a typo. |
|
|
| Report Abuse |
|
|
|
| 17 Apr 2016 03:31 PM |
the last parentheses is underlined in red and it says this...
15:31:26.950 - Workspace.Script:9: unexpected symbol near ')' |
|
|
| Report Abuse |
|
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Apr 2016 03:44 PM |
dont be so blind
just get rid of the comma
|
|
|
| Report Abuse |
|
|
| |
|