|
| 05 Jan 2016 08:01 PM |
This function works perfectly well, however, I can't seem to fix this issue: since I am using CFrame, the brick goes a few studs into another brick. How do I make it pop to the side? Also, if I position it right, it can go in a stud on top. I need to fix that also. I cannot use .Position because then it pops up and cannot be placed on the side of other blocks easily.
Mouse.Move:connect(function() if CurrentBlock.Name ~= Current.Name then CurrentBlock:Destroy() CurrentBlock = Current:Clone() CurrentBlock.Parent = workspace Mouse.TargetFilter = CurrentBlock end local Position = Mouse.Hit.p local Last = CurrentBlock.CFrame CurrentBlock.CFrame = CFrame.new((math.floor(Position.X) + 0.5), ((math.floor(Position.Y) + 0.5) + (CurrentBlock.Size.Y / 2)), (math.floor(Position.Z) + 0.5)) if (Player:DistanceFromCharacter(CurrentBlock.Position) > 45) then CurrentBlock.CFrame = Last end end) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 05 Jan 2016 09:09 PM |
| Add on to it half the size of the parts? (of course if it's rotated, it'll be a little more complicated than that) |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2016 09:46 PM |
| Stereotypes are not allowed |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2016 02:52 PM |
@cntkillme
The amount varies, and it's rotated :/ |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 06 Jan 2016 03:01 PM |
I'm ignoring your second issue for now; your first issue is quite interesting. You need to find out about how many stud units it is - no matter the rotation - to the next open space from a part. I solve this with a ray cast.
local R = Ray.new(RayBase.Position, RayBase.CFrame.lookVector * 100) local PartHit, PositionHit, NormalHit = workspace:FindPartOnRay(R) if (PartHit) then print(PartHit.Name) local ClosestRayPointToPartCenter = R.Unit:ClosestPoint(PartHit.Position) local PenetrationDistance = (ClosestRayPointToPartCenter - PositionHit).magnitude * 2 print("Ray went through " .. PenetrationDistance .. " units of material " .. PartHit.Material.Name) end
That will tell you about how many studs you need to push the block to make it come out the other side. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2016 03:03 PM |
| How do I know which direction to move it? |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 06 Jan 2016 03:03 PM |
R.Direction
Would be the direction to move it. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2016 03:04 PM |
| What type is the direction? I am assuming a Vector3 like with fromAxisAngle? |
|
|
| Report Abuse |
|
|
| |
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 06 Jan 2016 03:06 PM |
Yeah, it's a direction. You'd just do:
Part.Position = PartHit.Position + R.Direction * (PenetrationDistance/2)
|
|
|
| Report Abuse |
|
|
|
| 06 Jan 2016 03:06 PM |
| Wow, thanks. I am going to try this :D |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2016 03:11 PM |
Mouse.Move:connect(function() if CurrentBlock.Name ~= Current.Name then CurrentBlock:Destroy() CurrentBlock = Current:Clone() CurrentBlock.Parent = workspace Mouse.TargetFilter = CurrentBlock end local Position = Mouse.Hit.p local Last = CurrentBlock.CFrame CurrentBlock.CFrame = CFrame.new((math.floor(Position.X) + 0.5), ((math.floor(Position.Y) + 0.5) + (CurrentBlock.Size.Y / 2)), (math.floor(Position.Z) + 0.5)) if (Player:DistanceFromCharacter(CurrentBlock.Position) > 45) then CurrentBlock.CFrame = Last end local Ray = Ray.new(CurrentBlock.Position, (CurrentBlock.CFrame.lookVector * 100)) local PartHit, PositionHit = workspace:FindPartOnRay(Ray) if PartHit then local PenetrationDistance = ((Ray.Unit:ClosestPoint(PartHit.Position) - PositionHit).Magnitude * 2) CurrentBlock.Position = ((PartHit.Position + Ray.Direction) * (PenetrationDistance / 2)) end end)
It only works on one side and it just teleports really far away. |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 06 Jan 2016 03:14 PM |
"((PartHit.Position + Ray.Direction) * (PenetrationDistance / 2))"
Lol
(PartHit.Position) + (Ray.Direction * (PenetrationDistance / 2)) |
|
|
| Report Abuse |
|
|
|
| 08 Jan 2016 02:59 PM |
Nox, I have to say. You still failed me horribly :(
Mouse.Move:connect(function() if CurrentBlock.Name ~= Current.Name then CurrentBlock:Destroy() CurrentBlock = Current:Clone() CurrentBlock.Parent = workspace Mouse.TargetFilter = CurrentBlock end local Position = Mouse.Hit.p local Last = CurrentBlock.CFrame CurrentBlock.CFrame = CFrame.new((math.floor(Position.X) + 0.5), ((math.floor(Position.Y) + 0.5) + (CurrentBlock.Size.Y / 2)), (math.floor(Position.Z) + 0.5)) if (Player:DistanceFromCharacter(CurrentBlock.Position) > 45) then CurrentBlock.CFrame = Last end local Ray = Ray.new(CurrentBlock.Position, (CurrentBlock.CFrame.lookVector * 100)) local PartHit, PositionHit = workspace:FindPartOnRay(Ray) if PartHit then local PenetrationDistance = ((Ray.Unit:ClosestPoint(PartHit.Position) - PositionHit).Magnitude * 2) CurrentBlock.Position = ((PartHit.Position) + (Ray.Direction * (PenetrationDistance / 2))) end end)
Only works on 1 axis and it still pops far away to the side -_- |
|
|
| Report Abuse |
|
|
|
| 08 Jan 2016 03:00 PM |
you could get the surface type and use that
i did something similar and that worked fine for me |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 08 Jan 2016 03:01 PM |
I'm not going to bother looking at your code. I worked on that algorithm for someone on the dev forum. I know it works because I personally tested it. If you can't apply it correctly, what do I care?
"You still failed me horribly :("
It's not my job to integrate it with you code. |
|
|
| Report Abuse |
|
|
|
| 08 Jan 2016 03:03 PM |
You tell me if this works; it clearly doesn't. I implemented it perfectly, as far as I can tell.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse()
local Bricks = game.ReplicatedStorage.Bricks:GetChildren()
local Number = 1 local Current = Bricks[1]
game:GetService("UserInputService").InputBegan:connect(function(InputObject, GameProcessedEvent) if not GameProcessedEvent then if InputObject.UserInputType == Enum.UserInputType.Keyboard then if InputObject.KeyCode == Enum.KeyCode.E then Number = (Number + 1) if (Number == (#Bricks + 1)) then Number = 1 end Current = Bricks[Number] end end end end)
local CurrentBlock = Current:Clone() CurrentBlock.Parent = workspace
Mouse.TargetFilter = CurrentBlock
Mouse.Move:connect(function() if CurrentBlock.Name ~= Current.Name then CurrentBlock:Destroy() CurrentBlock = Current:Clone() CurrentBlock.Parent = workspace Mouse.TargetFilter = CurrentBlock end local Position = Mouse.Hit.p local Last = CurrentBlock.CFrame CurrentBlock.CFrame = CFrame.new((math.floor(Position.X) + 0.5), ((math.floor(Position.Y) + 0.5) + (CurrentBlock.Size.Y / 2)), (math.floor(Position.Z) + 0.5)) if (Player:DistanceFromCharacter(CurrentBlock.Position) > 45) then CurrentBlock.CFrame = Last end local Ray = Ray.new(CurrentBlock.Position, (CurrentBlock.CFrame.lookVector * 100)) local PartHit, PositionHit = workspace:FindPartOnRay(Ray) if PartHit then local PenetrationDistance = ((Ray.Unit:ClosestPoint(PartHit.Position) - PositionHit).Magnitude * 2) CurrentBlock.Position = ((PartHit.Position) + (Ray.Direction * (PenetrationDistance / 2))) end end)
Mouse.Button1Down:connect(function() CurrentBlock.Transparency = 0 CurrentBlock = Current:Clone() CurrentBlock.Parent = workspace Mouse.TargetFilter = CurrentBlock end) |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 08 Jan 2016 03:07 PM |
As I said, I'm not going through your code. I'm not that good to learn people's code that fast, sorry. Here's some proof of my tests:
prntscr(dot)com/9np101 prntscr(dot)com/9np165 prntscr(dot)com/9np1cg
That last one is actually demonstrating how accurate it is. That gray block is the length that the penetration distance returns. |
|
|
| Report Abuse |
|
|
|
| 08 Jan 2016 03:10 PM |
It doesn't work. I did exactly as you told.
I will wait for someone else.. |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 08 Jan 2016 03:11 PM |
| Good luck. It works fine, as I just showed you. |
|
|
| Report Abuse |
|
|
|
| 08 Jan 2016 03:12 PM |
| I'm testing nox7's method and it works fine. I think it's funny you think he'd insist his method so much and you think it's wrong. He's one of this forum's biggest math prodigies. |
|
|
| Report Abuse |
|
|
|
| 08 Jan 2016 03:12 PM |
you could try using body positions. and make the code way simpler.
thanks babe |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 08 Jan 2016 03:23 PM |
Here, I made a testing place you can check out. Uncopylocked.
http://www.roblox.com/games/341065776/Bullet-Penetration-Thickness-Calculation |
|
|
| Report Abuse |
|
|
|
| 08 Jan 2016 03:31 PM |
@IFrozen No, then it isn't immediate.
@XSmile
I think it's funny how your a noob; it isn't working for me. Now get out, your new here.
@Nox
I see what your saying; I can't seem to replicate it :(
Oh well, I give up. |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2016 12:22 PM |
you can cheat by making the speed fast enough so that it basicly looks like it teleported, tricks i use a lot
thanks babe |
|
|
| Report Abuse |
|
|