ashoulson / VolatilePhysics

A 2D Physics Library for Networked Games
Other
260 stars 44 forks source link

QueryCircle not working quite right #23

Open valorieschwartzdev opened 6 years ago

valorieschwartzdev commented 6 years ago

Hey there,

I just started using Volatile to do some basic collision checking for a 2D MMO I'm working on. I may be doing things incorrectly because I'm not too sure about the ins and outs of this library. I will try to explain how I'm doing things the best that I can.

I'm using Unity for my game client and PhotonServer / PhotonWire for my server application. I have my 2D world built in a Unity scene and have the tile collider data (which are just points because all tiles in my world are 1x1 squares) being saved to a json file that is readable / copy-able by the server application. I have successfully been able to create the game's world colliders and put them into a VoltBody, and have the server check if a player is going where they should not be able to go before moving them to their requested position. The world's body position is set to 0,0 because the points in the json data are relative to the scene's 0,0.

Now comes my problem with QueryCircle. I am working on some simple combat (player clicks mouse, sends request to server to "attack", server uses QueryCircle to check if there are any attack-able monsters and continues with the game logic of doing damage, etc.). However, it isn't returning any bodies at all.

I have set up a filter to ignore bodies that it shouldn't be checking (anything that isn't "attack-able") that I have confirmed is working. The problem seems to come with the fact that when I set the position of the monster's VoltBody, the worldAxes widths get set to something like -640, which kinda makes sense because the monster's world position is around 640,640. I've debugged the VoltCode through the QueryCircle call and noticed that when it calls Collision.FindAxisMaxPenetration, it fails because of the worldAxes widths.

I'm kinda clueless as to what could be the issue, and I wouldn't be surprised if it's because of the way I have things set up or I'm doing something incorrectly. If you could help me out with this, I'd greatly appreciate it.

Another note: When the monster is created on my server, it makes a shape using voltWorld.CreatePolygonBodySpace with vertices making a square (0,0 - 0,1 - 1,1 - 1, 0). Then, I use voltBody.CreateDynamicBody passing in the world position of the monster and the shape. The width is getting set to -640 somewhere when it translates the body's world position. I'm also using voltBody.Set to update the body's position, but at the moment the monster I am using is stationary. Thanks again.

EDIT: I've confirmed that a CircleCast works, just not QueryCircle. I need QueryCircle though because I want to allow the player to hit multiple monsters at once.