OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 25 Apr 2017 04:26 PM |
--[==[Hi guys. Looking for advanced scripters to help here. So, I have a wall, and depending on which side of it you're on, the direction a breach charge you place on it will be facing and its position will be different. I have the rotation part down, but how would I find which side of the wall the player's on? (I tried if (localTorso.Position.Z - wall.Position.Z) < 0) but that didn't work, obviously.) Note: all walls are the same size. Also, how would I move the breach charge to be on the side of the wall that the player's near? Thanks!]==]
local breachCharge = breachChargePrefab:Clone(); breachCharge.Parent = wall;
for _, child in pairs(breachCharge:GetChildren()) do child.CanCollide = false; child.Transparency = 1; end
if (localTorso.Position.Z - wall.Position.Z) < 0 then for _, child in pairs(breachCharge:GetChildren()) do child.Rotation = wall.Rotation; end breachCharge:TranslateBy(wall.Position - Vector3.new(breachCharge:GetModelCFrame().X, breachCharge:GetModelCFrame().Y, breachCharge:GetModelCFrame().Z) + Vector3.new(0, breachCharge:GetModelSize().Y / 2, 0)); elseif (localTorso.Position.Z - wall.Position.Z) >= 0 then for _, child in pairs(breachCharge:GetChildren()) do child.Rotation = wall.Rotation + Vector3.new(-180, 0, -180); end breachCharge:TranslateBy(wall.Position - Vector3.new(breachCharge:GetModelCFrame().X, breachCharge:GetModelCFrame().Y, breachCharge:GetModelCFrame().Z) + Vector3.new(0, breachCharge:GetModelSize().Y / 2, 0)); end |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2017 04:27 PM |
| https://www.roblox.com/library/168600454/getSurface |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 25 Apr 2017 04:34 PM |
| That doesn't solve my issue. I don't want to have to detect if the object was hit to do this. Also, I don't want 6 surface GUIs in each of my walls. |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2017 04:35 PM |
| It does solve your issue, the guis and hit are just an example of using it. Look at the script and learn how it works. |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 25 Apr 2017 04:36 PM |
| Alrighty, will do. Sorry, didn't mean to sound cold. |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
| |
|
|
| 25 Apr 2017 04:39 PM |
| Here I made the changes for you function getSurface(position, object) local surfaces = { back = object.CFrame * CFrame.new(0, 0, object.Size.Z); front = object.CFrame * CFrame.new(0, 0, -object.Size.Z); top = object.CFrame * CFrame.new(0, object.Size.Y, ### ###### = object.CFrame * CFrame.new(0, -object.Size.Y, 0); right = object.CFrame * CFrame.new(object.Size.X, 0, 0); left = object.CFrame * CFrame.new(-object.Size.X, 0, 0); } local surface = "back" for side, cframe in pairs (surfaces) do surface = ((position - cframe.p).magnitude > (position - surfaces[surface].p).magnitude and surface or side) end return surface end while true do wait() print(getSurface(game.Workspace.Player1.Torso.Position, script.Parent)) end |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2017 04:41 PM |
Here it is on pastebin /PzVinkYM
Also I didn't do function().p I did CFrame.p which is the position of a CFrame value. |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 25 Apr 2017 04:46 PM |
| Worked! Thanks, I'll just edit it into my script. Please don't leave yet, I might have more questions. |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 25 Apr 2017 05:18 PM |
Part of the script I updated (this only works with some walls. For others, it's opposite sides. Please help!):
function GetSurface(pos, object) local surfaces = { back = object.CFrame * CFrame.new(0, 0, object.Size.Z); front = object.CFrame * CFrame.new(0, 0, -object.Size.Z); top = object.CFrame * CFrame.new(0, object.Size.Y, 0); bo###### object.CFrame * CFrame.new(0, -object.Size.Y, 0); right = object.CFrame * CFrame.new(object.Size.X, 0, 0); left = object.CFrame * CFrame.new(-object.Size.X, 0, 0); } local surface = "back"; for side, cframe in pairs (surfaces) do surface = ((pos - cframe.p).magnitude > (pos - surfaces[surface].p).magnitude and surface or side); end return surface; end
function BreachWall() wall:WaitForChild("Interacting").Value = true; local breachCharge = breachChargePrefab:Clone(); breachCharge.Parent = wall; for _, child in pairs(breachCharge:GetChildren()) do child.CanCollide = false; child.Transparency = 1; end if GetSurface(localTorso.Position, wall) == "front" then for _, child in pairs(breachCharge:GetChildren()) do child.Rotation = wall.Rotation + Vector3.new(0, 90, 0); end breachCharge:TranslateBy(wall.Position - Vector3.new(breachCharge:GetModelCFrame().X, breachCharge:GetModelCFrame().Y, breachCharge:GetModelCFrame().Z) + Vector3.new(0, breachCharge:GetModelSize().Y / 2, 0)); elseif GetSurface(localTorso.Position, wall) == "back" then for _, child in pairs(breachCharge:GetChildren()) do child.Rotation = wall.Rotation + Vector3.new(0, -90, 0); end breachCharge:TranslateBy(wall.Position - Vector3.new(breachCharge:GetModelCFrame().X, breachCharge:GetModelCFrame().Y, breachCharge:GetModelCFrame().Z) + Vector3.new(0, breachCharge:GetModelSize().Y / 2, 0)); end |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 25 Apr 2017 05:19 PM |
See what I have so far here:
https://www.roblox.com/games/749435501/Siege |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 25 Apr 2017 05:29 PM |
Nvm, got it! Thanks for the help!
if GetSurface(localTorso.Position, wall) == "front" then for _, child in pairs(breachCharge:GetChildren()) do child.CFrame = wall.CFrame * CFrame.Angles(0, math.rad(-90), 0); end breachCharge:TranslateBy(wall.Position - Vector3.new(breachCharge:GetModelCFrame().X, breachCharge:GetModelCFrame().Y, breachCharge:GetModelCFrame().Z) + Vector3.new(0, breachCharge:GetModelSize().Y / 2, 0)); elseif GetSurface(localTorso.Position, wall) == "back" then for _, child in pairs(breachCharge:GetChildren()) do child.CFrame = wall.CFrame * CFrame.Angles(0, math.rad(90), 0); end breachCharge:TranslateBy(wall.Position - Vector3.new(breachCharge:GetModelCFrame().X, breachCharge:GetModelCFrame().Y, breachCharge:GetModelCFrame().Z) + Vector3.new(0, breachCharge:GetModelSize().Y / 2, 0)); end |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 25 Apr 2017 05:30 PM |
| Next, how would I position the charge to be in the middle of an object? |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2017 08:24 PM |
Do you want it in the middle of the object or in the middle of a certain facing of the object?
If you just want it in the middle of the object, put it in the same place as the object
If you want it on a certain facing, just set it in the same position as the object + (facingLookVector * (ObjectSizeOnThatAxis / 2)) |
|
|
| Report Abuse |
|
|