#Grid Script Doesn't work

1 messages · Page 1 of 1 (latest)

craggy delta
#

I made a script that made it when any object with a rigid body entered an empty game object which I will refer to as grid (image 1) it would snap that object that collided to the physical grid (image 2) aka making its value an integer and then clamping it so it doesn't get out of the grid

#

here's what I've got so far

worn wing
#

but where does gridVariable come from?

#

you are doing gridVariable = collier.ClosestPoint(gridVariable);

#

what is it before that? 🤔

craggy delta
worn wing
#

so what does gridVariable = collier.ClosestPoint(gridVariable); do?

craggy delta
#

I think it doesn't really do anything but somebody told me I should do it so

worn wing
#

what is scale of the grid transform?

#

the one with the big box collider

craggy delta
#

or the physical grid

#

the physical grid is actually a bunch of separate planes and I just selected all of them to make it clear

worn wing
#

as in your first screenshot

craggy delta
#

it's

worn wing
#

I wouldn't call it empty

#

it has a box collider.

craggy delta
#

the empty is 1 1 1 but the collider is x30 y20 z15

craggy delta
worn wing
#

first you want to get the apporximated collision position

#

gridVariable = collier.ClosestPoint(collider.transform.position);

craggy delta
#

and then

worn wing
#

then convert it into the box's local space like you did before with InverseTransformPoint

#

then you probably need to subtract the box collider's half size from that

#

so that "back left corner" becomes 0, 0, 0

#

then round it

worn wing
#

Vector3 localPos = transform.InverseTransformPoint(gridVariable);

craggy delta
worn wing
#

this is all i can say for now

#

try stuff out

craggy delta
#

ok

worn wing
#

and try to understand every step you do

#

guessing doesnt work

craggy delta
#

ok

worn wing
worn wing
#

cant just post a bunch of code without any explanation or question

craggy delta
#

so is this what you mean

#

it's what I understood from what you said

worn wing
#

send snippets or paste site, screenshots annoying

#

when i want to copy a line of yours

craggy delta
#

ok

#
Debug.Log("Collided");
        gridVariable = collider.ClosestPoint(collider.transform.position);
        Vector3 localPos = transform.InverseTransformPoint(gridVariable);
        gridVariable = (gameObject.transform.localScale / 2) - localPos;
        gridVariable = new Vector3(Mathf.RoundToInt(gridVariable.x), 0, Mathf.RoundToInt(gridVariable.z));  
        collider.transform.position = gridVariable;
        Debug.Log("Ran");```
worn wing
#

oh btw

craggy delta
#

so is this what you meant

#

on your explanation

craggy delta
worn wing
#

im literally typing

craggy delta
#

sry

worn wing
#

you should actually replace
gridVariable = collider.ClosestPoint(collider.transform.position);
with
gridVariable = selfCollider.ClosestPoint(collider.transform.position);

#

where selfCollider is the box collider of the "empty"

craggy delta
#

ok

#

self collider doesn't exist

worn wing
#

🤦‍♂️

worn wing
#

you skip every second message i send

#

I don't have time to spoonfeed you, good luck

craggy delta
#

yeah I realized

craggy delta
#

ykw this isn't worth wasting time on