skyarexJoin Date: 2010-03-21 Post Count: 12989 |
How can you make a touch event work between two objects?
I don't mean between a humanoid and brick, I mean between two bricks. I have been struggling to make it work.
"Don't Panic"- HHGTTG |
|
ayub32Join Date: 2009-12-27 Post Count: 485 |
script.Parent.Touched:connect(function(hit)
if hit.Parent:IsA("Part") then
--stuff
end
end) |
|
skyarexJoin Date: 2010-03-21 Post Count: 12989 |
@Ay
That only works if it isn't touching anything I think. However the brick I have is touching the ground. How would this work?
"Don't Panic"- HHGTTG |
|
|
script.Parent.Touched:connect(function(thing)
print (script.Parent.Name.." and "..thing.Name.." have touched")
end)
So if this was in:Part1
And it hit:Part2
Ouput would be:
-Part1 and Part2 have touched |
|
skyarexJoin Date: 2010-03-21 Post Count: 12989 |
@Ay
It doesn't work.
"Don't Panic"- HHGTTG |
|
|
name the part you want to check "BlockToCheck"
script.Parent.Touched:connect(function(hit)
if hit:IsA("Part") and hit.Name == "BlockToCheck" then
--stuff
end
end) |
|
skyarexJoin Date: 2010-03-21 Post Count: 12989 |
@island
Nothing is happening.
"Don't Panic"- HHGTTG |
|
|
Once it actually"touches" it'll do ittry inserting that script into a part,then put a part a few studs above it,and hit play.. |
|
|
Of course its not gonna run if the part is sitting on the baseplate,and u expect it to say part touched baseplate..and BTW,ever hear of output? |
|
skyarexJoin Date: 2010-03-21 Post Count: 12989 |
@mario
Nothing happened.
"Don't Panic"- HHGTTG |
|
|
Did you replace "--stuff" with some code? |
|
skyarexJoin Date: 2010-03-21 Post Count: 12989 |
>Once it actually"touches" it'll do ittry inserting that script into a part,then put a part a few studs above it,and hit play..
What?
>Of course its not gonna run if the part is sitting on the baseplate,and u expect it to say part touched baseplate..and BTW,ever hear of output?
Well, considering i am using the print function in order to tell if the script works...in fact forget it. I am not even going to justify that stupidity with an answer.
"Don't Panic"- HHGTTG |
|
BokkenJoin Date: 2010-01-10 Post Count: 194 |
Are you talking about detecting collisions that have already occurred? As in, the blocks are already touching prior to the script being ran? |
|
skyarexJoin Date: 2010-03-21 Post Count: 12989 |
>Are you talking about detecting collisions that have already occurred? As in, the blocks are already touching prior to the script being ran?
Yes, basically.
"Don't Panic"- HHGTTG |
|
7y13rbJoin Date: 2011-05-28 Post Count: 223 |
function onTouched(otherPart)
if otherPart.Name ~= "Baseplate" then
--stuff
end
end
script.Parent.Touched:connect(onTouched) --something like this, i think... |
|
BokkenJoin Date: 2010-01-10 Post Count: 194 |
Assuming they're connected by some surface connection you can use the following,
pastebin.com/vZGGgATP
otherwise you'll have to create an algorithm to detect the intersection of arbitrary oriented shapes, which could be fairly difficult. |
|
|
Ok,so here's an idea then..wow,plz next time,be more specific,it seemed like u were asking for an ontouch function to me..
part = script.Parent
touching=false
while not touching do
wait(0.1)
for I,v in pairs (Workspace:GetChildren()) do
if v.Name ~= script.Parent.Name and v:IsA("Part") then
if v.Position.Y-script.Parent.Position.Y-1 then
print "close togther"
end
end
end
Something like this maybe? |
|
BokkenJoin Date: 2010-01-10 Post Count: 194 |
Was the issue resolved with my example script? If not I can help you further. |
|
skyarexJoin Date: 2010-03-21 Post Count: 12989 |
@Brokken
Yeah, I put it in the part and nothing happened. Nothing showed up on the output :(
"Don't Panic"- HHGTTG |
|
BokkenJoin Date: 2010-01-10 Post Count: 194 |
Can you describe the context of the situation a little more? Are the parts connected by a surface joint, are they arbitrarily orientated in space and you'd just like to know whether they're colliding/touching or are they axis aligned? |
|
|
add a fire or something that isnt in most objects and ontouch check if it has that object |
|