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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: help with position/vector3.

Previous Thread :: Next Thread 
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
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
AStoryUntold is not online. AStoryUntold
Joined: 09 Mar 2013
Total Posts: 237
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
AStoryUntold is not online. AStoryUntold
Joined: 09 Mar 2013
Total Posts: 237
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
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
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
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
17 Apr 2016 01:11 PM
Divide the y by 2.
Report Abuse
AStoryUntold is not online. AStoryUntold
Joined: 09 Mar 2013
Total Posts: 237
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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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
direMitten is not online. direMitten
Joined: 18 Jun 2015
Total Posts: 1294
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
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
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
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
17 Apr 2016 02:47 PM
b
Report Abuse
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
17 Apr 2016 02:59 PM
could someone please help me?
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
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
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
17 Apr 2016 03:42 PM
b :P
Report Abuse
TimeTicks is not online. 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
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
17 Apr 2016 04:18 PM
thx i love u
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