|
| 07 Jun 2016 11:30 AM |
Hey! Does anybody know what basic math should fix this?
So I have a placing system, you take an item from the inventory and you drag it around your planet by mouse. 4x4 items align perfectly, but bigger items go over the border. Can somebody help? I currently have something like this:
if mouse.Hit.p.X > planet.Position.X - (52-item.Hitbox.Size.X) and mouse.Hit.p.X < planet.Position.X + (53-item.Hitbox.Size.X) and mouse.Hit.p.Z > planet.Position.Z - (52-item.Hitbox.Size.Z) and mouse.Hit.p.Z < planet.Position.Z + (53-item.Hitbox.Size.Z) then
|
|
|
| Report Abuse |
|
|
| |
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 07 Jun 2016 12:49 PM |
If ur looking for an incremented movement then, local inc = 4 --4 Studs local tar = Mouse.Hit.p Object.Position = Vector3.new(tar.X - (tar.X % inc), tar.Y - (tar.Y % inc), tar.Z - (tar.Z % inc)) Try this. |
|
|
| Report Abuse |
|
|
| |
|
|
| 07 Jun 2016 12:54 PM |
I got the increment, everything works, but some models go over the border of the base and some parts cant go further until the border
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 07 Jun 2016 02:11 PM |
| Well u could increment based on the edges rather than the center of the part, but that would be more complex too. |
|
|
| Report Abuse |
|
|
|
| 08 Jun 2016 02:41 AM |
| How could I do that? (sorry I'm a bit noob at this part) |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 10 Jun 2016 08:40 AM |
local inc = 1 local left = Object.CFrame * Vector3.new(Object.Size.X / 2) local bottom = Object.CFrame * Vector3.new(0, Object.Size.Y / 2) local front = Object.CFrame * Vector3.new(0, 0, Object.Size.Z / 2) local leftRemain = left.X % inc local bottomRemain = bottom.Y % inc local frontRemain = front.Z % inc Object.CFrame = Object.CFrame + Vector3.new(-leftRemain, -bottomRemain, -frontRemain)
Something like this. |
|
|
| Report Abuse |
|
|
|
| 12 Jun 2016 12:16 PM |
| Ok thanks! I'll try to work something out |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 12 Jun 2016 04:27 PM |
| Np, tell me if u need further assistance. |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2016 12:07 PM |
Ummm... I can't really use CFrame, cause I use models. ALL of them are models. I don't need incremention actually, I just need to check if the item I'm placing, isn't over the border of my base, regardless of the size and rotation of the model. |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 13 Jun 2016 05:39 PM |
| Well ur choice, u could use GetExtentSize() I think it's called if u wanted it to however... |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
| |
|
|
| 14 Jun 2016 06:32 AM |
| Well... GetExtentsSize doesn't help me :/ |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 14 Jun 2016 04:36 PM |
| Lol, u can just find the average number for each axis, that always returns the middle number, so it should give us the middle position of a model. Though I don't know if u would find any use for that, but anyway, ur choice, my job is to suggest. |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 14 Jun 2016 05:22 PM |
| why did u ignore my post about getmodelsize |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 15 Jun 2016 10:31 AM |
API:Class/Model/GetModelSize < API:Class | Model Deprecated: This item is deprecated. Do not use it for new work.
API:Class/Model/GetExtentsSize < API:Class | Model Function of Model icon.pngModel Vector3 GetExtentsSize ()
So as u can see the function I posted isn't deprecated but urs is. |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
| |
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 16 Jun 2016 12:39 PM |
K so, u say edges... k...
local function getCenter(model) local p = Vector3.new() local ch = model:GetChildren() for i, v in pairs(ch) do if v:IsA('BasePart') then p = p + v.Position end end p = p / #ch end
local function ray(pos, object) local r = Ray.new(pos, pos + Vector3.new(0, -100, 0)) local hit = workspace:FindPartOnRay(r, object) return hit end
local function checkDirections(center, size, object) local left, right = center - Vector3.new(size.X) / 2, center + Vector3.new(size.X) / 2 local up, down = center - Vector3.new(0, size.Y) / 2, center + Vector3.new(0, size.Y) / 2 local back, front = center - Vector3.new(0, 0, size.Z) / 2, center + Vector3.new(0, 0, size.Z) / 2 if ray(left, object) then return end if ray(right, object) then return end if ray(up, object) then return end if ray(down, object) then return end if ray(back, object) then return end if ray(front, object) then return end return true end
--Event on which u move the object local oldPosition = getCenter(Model) --Assuming 'Model' is defined --Move the model with the increments and stuff local center = getCenter(Model) if not checkDirections(center, Model:GetExtentSize(), Model) then --Move it back to 'oldPosition' end --End
Something like this. |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 16 Jun 2016 12:43 PM |
Oops, a few mistakes I made.
local r = Ray.new(pos, pos + Vector3.new(0, -100, 0)) -100 I guess is a bit too much as I'm sure no model would be that big. Change it to like local r = Ray.new(pos, Vector3.new(0, -10, 0))
All these if ray(left, object) then return end if ray(right, object) then return end if ray(up, object) then return end if ray(down, object) then return end if ray(back, object) then return end if ray(front, object) then return end Should be like this if not ray(left, object) then return end So place a 'not' straight after each 'if'
Also, I forgot about the ray thing that I could have given it the size to determine how long the ray should be, but it's not that important. |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2016 12:59 PM |
local left, right = center - Vector3.new(size.X) / 2, center + Vector3.new(size.X) / 2 This line says: bad argument #1 to '?' (Vector3 expected, got nil)
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 16 Jun 2016 01:05 PM |
My bad...
local function getCenter(model) local p = Vector3.new() local ch = model:GetChildren() for i, v in pairs(ch) do if v:IsA('BasePart') then p = p + v.Position end end return p / #ch end
local function checkDirections(center, size, object) local left, right = center - Vector3.new(size.X) / 2, center + Vector3.new(size.X) / 2 local up, down = center - Vector3.new(0, size.Y) / 2, center + Vector3.new(0, size.Y) / 2 local back, front = center - Vector3.new(0, 0, size.Z) / 2, center + Vector3.new(0, 0, size.Z) / 2
if not checkDirections(center, Model:GetExtentsSize(), Model) then
All of these are fixed, replace these... u should know where to put these 3 chunks ;) |
|
|
| Report Abuse |
|
|
razvan634
|
  |
| Joined: 30 Jan 2014 |
| Total Posts: 590 |
|
| |
|
| |
|
|
| 16 Jun 2016 01:18 PM |
Now the model doesn't even move to my planet...
|
|
|
| Report Abuse |
|
|