#```
1 messages · Page 1 of 1 (latest)
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
so bounds.center for center argument?
a valid use would be something like Collider[] hits = Physics.OverlapBox(bounds.center, bounds.extents, Quaternion.identity, shipLayerMask);
when i try it and make so the ship is between the 2 points it doesnt work
i mean this value printed gives empty list
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);
}
one should be larger than the ship'd position and one should be smaller
why are you raycasting?
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.
endPosition = Camera.main.ScreenToWorldPoint(ray.GetPoint(distance));
like that?
3d game actualy
where is this ray coming from?
camera
📃 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.
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
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?
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
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..
you're just printing the array
that won't show anything
loop over it and print each item
you're welcome (:
oh i am stupid