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: Region3 and Vector3

Previous Thread :: Next Thread 
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 10:49 AM
hi is where a way if a Vector3 lies within a Region3?

This would help me to cut the size of some scripts down massivly if i can use Region3 Values.

so yea is there any way of seeing if a Vector3 value lies within a Region3 Value
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 11:18 AM
bump ^.^
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
29 Jul 2012 11:22 AM
Could you just use basic intersection?
local vec = Vector3.new(0, 0, 0);
local reg = Region3.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 0));

local regPos = reg.CFrame.p;
local regSize = reg.Size;

local regPos0 = regPos + (regSize / 2);
local regPos1 = regPos - (regSize / 2);

local intersectX = (vec.x > regPos0.x) and (vec.x < regPos1.x);
local intersectY = (vec.y > regPos0.y) and (vec.y < regPos1.y);
local intersectZ = (vec.z > regPos0.z) and (vec.z < regPos1.z);

local collision = intersectX and intersectY and intersectZ;


(Completely untested so no idea if it will work)

Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 11:24 AM
il give it a go thanks :)
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 11:57 AM
i just tried and it kept on saying false no matter weather the ve3c was within or outside of the region :/
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
29 Jul 2012 11:59 AM
No idea :/
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 12:02 PM
ok thanks :)
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 12:06 PM
i done a small change and it works :) thanks alot ^.^


local intersectX = (vec.x < regPos0.x) and (vec.x > regPos1.x);
local intersectY = (vec.y < regPos0.y) and (vec.y > regPos1.y);
local intersectZ = (vec.z < regPos0.z) and (vec.z > regPos1.z);
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
29 Jul 2012 12:09 PM
Oh, lol - this is why I fail at 2d collision in simple platform games :P
Yw :D
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 12:20 PM
:D

ive condenced it a bit aswell to make it more suitable for me :) and thanks alot :D
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
29 Jul 2012 12:21 PM
Yw :D :D :D
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 12:27 PM
there we go :)

function isInRegion(re,ve)
if (re) and (ve) then
local rP0 = re.CFrame.p + (re.Size / 2);
local rP1 = re.CFrame.p - (re.Size / 2);
local collision = (ve.x < rP0.x) and (ve.x > rP1.x) and (ve.y < rP0.y) and (ve.y > rP1.y) and (ve.z < rP0.z) and (ve.z > rP1.z)
return collision
else
return false
end
end
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