|
| 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 |
|
|
| |
|
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 |
|
|
| |
|
|
| 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
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
| |
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
| |
|
|
| 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 |
|
|