tkddude2
|
  |
| Joined: 17 Mar 2011 |
| Total Posts: 28 |
|
|
| 22 Dec 2015 02:28 PM |
Is there a touched event for parts that are Anchored and CFramed?
Touched events do not work for parts that are CFramed and anchored, as stated in the the wiki. This event does not fire if the part is being CFramed through something. (This is an excerpt from the wiki). My real problem is I have many parts flying around using BodyForces, and this creates a lot of physics lag. Unanchoring the 'bullet' makes the event fire, but glitches out the bullet itself. I have thought about using RenderStepped:wait()(something like that) so that each frame it isn't glitching out, but this would create the same amount of lag I had to start with. Is there any other way to have an event that acts just like a Touched event would?
--Here's part of the script. lazer = script.Parent lazer.Touched:connect(function(otherPart)
end)
|
|
|
| Report Abuse |
|
|
|
| 22 Dec 2015 02:30 PM |
| You'd need to create your own system. The reason the event doesn't fire is because the physics for it isn't being simulated, the game doesn't create any collisions. |
|
|
| Report Abuse |
|
|
tkddude2
|
  |
| Joined: 17 Mar 2011 |
| Total Posts: 28 |
|
|
| 22 Dec 2015 02:34 PM |
| Alright, do you know how to do that? The only way I can think to do that is to iterate through each part and use the size and position of each part to see if they collide, which I assume is very inefficient. |
|
|
| Report Abuse |
|
|
|
| 22 Dec 2015 02:40 PM |
| It is inefficient, but it's the most efficient way. That's why large collision events cause a lot of lag. It's calculating physics and collisions for every single one of those bricks. |
|
|
| Report Abuse |
|
|
tkddude2
|
  |
| Joined: 17 Mar 2011 |
| Total Posts: 28 |
|
|
| 22 Dec 2015 02:55 PM |
I've found and edited this together for testing, but it is quickly defeated by two things. 1. If one of the parts is rotated 2. If I have a Union and set it's collision fidelity to hull, it ignores this.
Any way to fix either?
local ma = math.abs local function IsColliding(part1, part2) local p1s = part1.Size local p1p = part1.Position local p2s = part2.Size local p2p = part2.Position local dx = (p1s.x+p2s.x)/2 local dy = (p1s.y+p2s.y)/2 local dz = (p1s.z+p2s.z)/2 if ((ma(p1p.x-p2p.x) <= dx) and (ma(p1p.y-p2p.y) <= dy) and (ma(p1p.z-p2p.z) <= dz)) then print(true) --return true else print(false) --return false end end
while true do wait() IsColliding(game.Workspace.Part, game.Workspace.Part2) end
|
|
|
| Report Abuse |
|
|
tkddude2
|
  |
| Joined: 17 Mar 2011 |
| Total Posts: 28 |
|
|
| 22 Dec 2015 02:56 PM |
This post seems to be having the same problem. http://forum.roblox.com/Forum/ShowPost.aspx?PostID=137007563 |
|
|
| Report Abuse |
|
|
tkddude2
|
  |
| Joined: 17 Mar 2011 |
| Total Posts: 28 |
|
|
| 22 Dec 2015 03:11 PM |
| Another solution maybe is to clone the bullet and weld it to itself(and the clone isn't anchored) and then have the clone pick up on collision. Or would that still lag out the physics? |
|
|
| Report Abuse |
|
|
tkddude2
|
  |
| Joined: 17 Mar 2011 |
| Total Posts: 28 |
|
|
| 22 Dec 2015 03:18 PM |
For anyone who is curious, I ended up unanchoring the part, and cframing it every frame using game:GetService("RunService").RenderStepped:wait() |
|
|
| Report Abuse |
|
|
hkep
|
  |
| Joined: 19 Jul 2014 |
| Total Posts: 550 |
|
|
| 22 Dec 2015 03:40 PM |
lazer = script.Parent -- shoot lazer whenever
-- client sided -- local Char -- = get the local character local Lazers -- = put all lazers in a folder in workspace
local function GetBody(Char) local P = {}; local C = Char:GetChildren(); for i=1,#C,1 do local part = C[i]; if part:IsA("Part") and not (part.Name == "HumanoidRootPart") then table.insert(P,part); end end return P; end;
local Body = GetBody(Char);
local function OnTouched(Part) if (Part.Parent == Lazers) then -- take damage end; end;
for i=1,#Body,1 do local Part = Body[i]; Part.Touched:connect(OnTouched) end;
|
|
|
| Report Abuse |
|
|
hkep
|
  |
| Joined: 19 Jul 2014 |
| Total Posts: 550 |
|
|
| 22 Dec 2015 03:43 PM |
| i forgot, you cant do a .Touched event from a local script. You will have to put the code in a global script in the player's character. And, of coarse, put it in character every time they spawn. |
|
|
| Report Abuse |
|
|