#```

1 messages · Page 1 of 1 (latest)

rain spire
#

you have copied the function signature for OverlapBox into your code, hence the Vector3's floating around

#

Bounds.Encapsulate returns void, so this is invalid

#

you use the Encapsulate method to update the Bounds object

#

then, once the bounds have all the points you need, you can use the Bounds object to get the center and extents for the box query

vague bobcat
#

so bounds.center for center argument?

rain spire
#

a valid use would be something like Collider[] hits = Physics.OverlapBox(bounds.center, bounds.extents, Quaternion.identity, shipLayerMask);

vague bobcat
#

when i try it and make so the ship is between the 2 points it doesnt work

rain spire
#

well, show your code

#

and use Debug.Log to make sure the values make sense

vague bobcat
rain spire
#

yes, I understand

#

use Debug.Log to check that the corners make sense

vague bobcat
#
if (plane.Raycast(ray, out distance))
            {
                endPosition = ray.GetPoint(distance);
                //check for collision with a ship
                Vector3 diff = startPosition - endPosition;
                diff.x = Mathf.Abs(diff.x);
                Bounds bounds = new();
                bounds.Encapsulate(diff);
                Collider[] hits = Physics.OverlapBox(bounds.center, bounds.extents, Quaternion.identity, shipLayerMask); 
                Debug.Log(hits);

            }
rain spire
#

one should be larger than the ship'd position and one should be smaller

#

why are you raycasting?

vague bobcat
#

to get the second point

#

like where player releases mouse

rain spire
#

you should just convert the cursor position to world space when you start and stop dragging

#

Camera.main.ScreenToWorldPoint can convert the mouse position to a world position

#

I am assuming this is a top-down 2D game with an orthographic camera.

vague bobcat
#
endPosition = Camera.main.ScreenToWorldPoint(ray.GetPoint(distance));

like that?

rain spire
#

where is this ray coming from?

vague bobcat
#

camera

rain spire
#

show me your entire script

#

!code

zenith phoenixBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

vague bobcat
rain spire
#

ah, okay, I undestand what's going on now

#

I would double-check that the positions make sense

#

you could even do something like this

#
new GameObject().transform.position = startPosiiton;
#

this would create a new empty object and stick it at startPosition

#

look at where the two empties wind up

vague bobcat
#

i see, gonna try it\

#

all good here i think...

#

both on y 0 btw

#

it must be sth wrong here then:

#
Vector3 diff = startPosition - endPosition;
diff.x = Mathf.Abs(diff.x);
Bounds bounds = new();
bounds.Encapsulate(diff);
Collider[] hits = Physics.OverlapBox(bounds.center, bounds.extents, Quaternion.identity, shipLayerMask); 
#

@rain spire are you sure that the OverlapBox is done correctly?

rain spire
#

oh, that's not right

#

use Bounds bounds = new(startPosition, Vector3.zero);

#

then bounds.Encapsulate(endPosiiton);

#

You're making a box that encapsulates [0,0,0] and diff

vague bobcat
#
if (plane.Raycast(ray, out distance))
            {
                endPosition = ray.GetPoint(distance);
                new GameObject().transform.position = endPosition;
                //check for collision with a ship
                Vector3 diff = startPosition - endPosition;
                diff.x = Mathf.Abs(diff.x);
                Bounds bounds = new(startPosition, Vector3.zero);
                bounds.Encapsulate(endPosition);
                Collider[] hits = Physics.OverlapBox(bounds.center, bounds.extents, Quaternion.identity, shipLayerMask); 
                print(hits);

            }
#

still not working...

#

wait

#

one more chance..

rain spire
#

you're just printing the array

#

that won't show anything

#

loop over it and print each item

vague bobcat
#

kekwait oh i am stupid

#

YESS!!

#

TYSM!

rain spire
#

you're welcome (: