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: Is there a way to tell which surface is touched...

Previous Thread :: Next Thread 
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
24 Nov 2013 10:15 PM
with the Touched event?

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
24 Nov 2013 10:21 PM
Example:
--
script.Parent.TopSurface.Touched:connect(function(hit)
print(hit.Name)
end)
--
If a part hits the top of script.Parent it prints the part's name.

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
25 Nov 2013 06:16 PM
Bump.

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
Report Abuse
PerpetualMovement is not online. PerpetualMovement
Joined: 04 Dec 2012
Total Posts: 1001
25 Nov 2013 06:24 PM
What do you mean by surface, as in the top surface of a part? If so, I don't think you can do that unless you make a thin invisible brick on top of a part, and check when they touch the invisible brick.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 06:24 PM
^ Or use simplish math.

TopSurface would be position + (size.y/2) or something like that
Report Abuse
PerpetualMovement is not online. PerpetualMovement
Joined: 04 Dec 2012
Total Posts: 1001
25 Nov 2013 06:28 PM
Well that wouldn't really work with a Touch. You can't touch a position but you can use a loop to check your position but that may cause lag.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 06:28 PM
Yes it would.

hit.Position
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
25 Nov 2013 06:41 PM
Support this thread please:
http://www.roblox.com/Forum/ShowPost.aspx?PostID=118708187

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 06:42 PM
No, how would that work with walk-through parts?
Exactly
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
25 Nov 2013 06:44 PM
@cnt
Whatever surface was touched first.

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 06:45 PM
How would that work if you get teleported into the object
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
25 Nov 2013 06:47 PM
A new surface perhaps?
InsideSurface

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 06:48 PM
lol or just use pretty basic math
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
25 Nov 2013 06:50 PM
^
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
25 Nov 2013 06:54 PM
getLeast = function(tab)
startnum = math.huge
ind = 0
if type(tab) == "table" then
for i, v in pairs(tab) do
if type(v) == "number" and v < startnum then
startnum = v
ind = i
end
end
end
return startnum ~= math.huge and startnum, ind or startnum == math.huge and "error"
end
--
getSurfaceHit = function(obj, hitter)
SurfaceTable = {"FrontSurface", "BackSurface", "RightSurface", "LeftSurface", "TopSurface", "BottomSurface"}
local lengthx = obj.Size.X/2
local lengthy = obj.Size.Y/2
local lengthz = obj.Size.Z/2
local front = (obj.CFrame*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthz))
local back = (obj.CFrame*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*-lengthz))
local right = (obj.CFrame*CFrame.Angles(0, math.rad(-90), 0))*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthx)
local left = (obj.CFrame*CFrame.Angles(0, math.rad(90), 0))*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthx)
local top = (obj.CFrame*CFrame.Angles(math.rad(90), 0, 0))*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthy)
local bottom = (obj.CFrame*CFrame.Angles(math.rad(-90), 0, 0))*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthy)
--
local num, index = getLeast({(hitter.Position-front).magnitude, (hitter.Position-back).magnitude, (hitter.Position-right).magnitude, (hitter.Position-left).magnitude, (hitter.Position-top).magnitude, (hitter.Position-bottom).magnitude})
print(num, index, SurfaceTable[index])
return SurfaceTable[index]
end

-- Example Usage:
for i, v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:connect(function(hit)
surface = getSurfaceHit(v, hit)
print(surface)
v[surface] = "Studs"
end)
end
end


-- Not mine
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 06:55 PM
That is way to inefficient...
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
25 Nov 2013 06:58 PM
Don't tell me, I didn't make it.
You're the best scripter here.
I saw it posted a long while ago and remembered it. http://www.roblox.com/Forum/ShowPost.aspx?PostID=96530849
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 07:00 PM
I'm not the best but there have been better ways then chaos's
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
25 Nov 2013 07:02 PM
Who's better than you qq
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 07:03 PM
There is a lot, I'm just the most active on this sub-forum I would assume
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
25 Nov 2013 07:07 PM
You mean... you're the most active best scripter in scripting helpers?
Well sure.
You make me feel small :/
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 07:08 PM
No, I said I'm probably the most active compared to a lot of the people.
I didn't mean the active best...
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
25 Nov 2013 07:09 PM
Then I jump back to my question
Then who is ;o
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
25 Nov 2013 07:10 PM
There is no best, there is always someone better than myself and yourself. And I don't know who the best is...
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
25 Nov 2013 07:11 PM
Best = Sorcus
'Nuff said.

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
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