• Content count

  • Joined

  • Last visited

Community Reputation

354 Neutral

About CelticSir

  • Rank

Personal Information

  • Interests
  1. Hi I have a basic setup currently where i create a quadratic bezier curve, and then i do 100 steps across the curve to calculate its distance. And from that i do distance / 3 to give me the total number of segments. Its pretty quick but its not a good solution for very large distances (too many segments) and then for very small distances (too few segments). Here is a visual issue of the problem: 7 looks reasonable (though i actually think it computed 6 my mistake), but for something much shorter 2 simply doesn't cut it neither would 3 or 4 to be honest. So i am wondering what is a common way to balance this so they are smooth regardless of length and sharpness of the angle ? I use C# but I'm just looking for a logical approach here not how to implement it in code since i'm sure i can handle that myself Thanks in advance.
  2. Hi I have set up my TcpClient to connect to my server and that works fine. But i am a bit confused how i read messages from the network stream with it continuously running via async, without ever closing the connection ? My TcpClient Manager class has: public async Task<bool> Connect(string address, int port) { try { await _tcpClient.ConnectAsync(address, port); IsConnected = true; return true; } catch(Exception e) { Debug.Log(e); return false; } } public async Task<int> Read(byte[] readBuffer) { if (!IsConnected) return -1; using (var networkStream = _tcpClient.GetStream()) { try { var bytesRead = await networkStream.ReadAsync(readBuffer, 0, readBuffer.Length); return bytesRead; } catch (Exception e) { Debug.Log(e); IsConnected = false; return -1; } } } So i thought to just run a co-routine and call Read constantly to get the most recent message, but that doesn't make much sense to me since a co-routine would be blocked with the await. How is this actually done? The MS Docs don't have very good Async examples with the TcpClient class so i don't know fully get how to keep calling Read correctly.
  3. Hi I have a very basic prototype in unity of a game where by I fire a projectile with a obstacle in the environment that moves blocking its trajectory. Due to the fact that time between events is obviously not instant between clients i have a slight issue where one user shoots the projectile and hits the target, but the other player sees it miss the target entirely. Picture to explain better: The main problem is that the position of the moving obstacle is not in the same position "now" upon the firing event received for client B as it was for client A.This is not an FPS or something like that, the moving obstacle is part of the environment rather than another player. So i am thinking i should be able to get this moving obstacle sync'd far better than i could with player positions. Now i know this is not 100% solvable due to the nature of networks but am wondering what solutions i can implement to reduce the amount of error for this.
  4. Hello I am learning networking at the moment and just in the middle of sending client positions to the server every x amount of milliseconds. But this is a fair bit of bytes to send quite a lot. So i wondered about sending just keyboard and mouse inputs to the server instead of the position updates, since this would be a lot less bytes. Yet it seems most games don't use this method, they tend to send position updates instead. I am curious what pros and cons there are between these 2 options? I feel like i might be over looking something here because sending the keyboard and mouse inputs seem to be at first glance a simpler approach and less bandwidth too. The game is an FPS so it needs to be real time aswell. So is there some issue with just sending keyboard/mouse inputs rather than positions that i am not fully grasping due to lack of experience with this?
  5.   Physics2D.OverlapBox has an angle parameter for rotation. But writing it from scratch for educational purposes is perfectly respectable imo.     Would the angle parameter be for the box you are applying on top of existing colliders? The colliders would need to be rotated and then do a point overlap rather than a box for raycasting no?
  6.   The physics system is very efficient, especially if you user layer masks intelligently. The size of your environment shouldn't matter much. And the Physics2D library essentially mirrors its 3D counterpart, so you can just use Physics2D.OverlapBox. If you're insistent on not using the physics system (I tend to avoid it but in the case of pure raycasting and intersection checks I find it's very useful), I guess you'll just have to write your own OBB logic     Yeah thats the best way to learn :) Plus even if i did use their system. It would be of no use for rotated objects anyway unless i use 3D colliders.
  7.   Unity's raycasting handles rotated boxes fine as far as I know, so why is detecting a mouse ray a problem? And for collision detection, what's wrong with Physics.OverlapBox? https://docs.unity3d.com/ScriptReference/Physics.OverlapBox.html I might just not be understanding the problem correctly, but based on the image you posted it shouldn't be an issue in Unity.     Well i am not using colliders and even if i do, 2D colliders are not rotated they are axis aligned so they would be like the second example in the image when i need the third example. I just have a bounds type and a general ray casting method currently. If the object is rotated the bounds isn't accurate to the object as per the image i posted (the second one is where the issue lies) so i get issues. The hit point may be in the bounds but not in the actual segment. Hope that makes sense. Since the objects are static on the x:z plane and non moving theres no point in 3D colliders or even 2D colliders, using the physics engine is wasted performance and my environment is pretty big it won't be feasible for me to use it.. I was hoping to make it more optimised by checking if the point hits the bounds but making sure the bounds was accurate to the segment (the third example in the image).
  8. Yes, but it reduces the problem from N*N tests to a few interesting cases, and it's bloody fast. If a single test doesn't seem feasible, find another way, for example, by splitting the problem. First try to eliminate all cases that are obviously non-overlapping, then for a few cases that might overlap, do a second test in some way. I find this the most rewarding part of programming, figuring out a way to solve a problem that looks impossible at first. If you split the problem, for the first test, bounding box works nicely, it's fast enough for large quantities of areas, and it doesn't yield false negatives. It ends with a bunch of 2 particular shapes that might match. That problem is much simpler than matching zillions of shapes with each other. That's progress!! (If an idea doesn't solve the entire problem, don't discard it and stare yourself blind at its failure, it may be tweaked or used as building block in a larger context.) Likely that second test depends on the shape of the two areas. If you have a lot of boxy shapes, you may want to make a dedicated test for that (your bounding box could be made to fit exactly if you exclude the triangles that are not covered). One other possible direction is to repeat the bounding box trick, but with several smaller boxes (several sub-boxes together make up the shape). You can perhaps try some line segment test too. Likely there is prior art in resolving collisions between exactly 2 shapes.     Well i can understand the quad tree is useful, but i am confused why unity bounds has to be axis aligned and not related to the rotation of the transform - it seems to be world space not local space which i find really strange. It doesn't seem like an easy calculation to check if the ray hits the two triangles outside the segment.  If i can get it like the second example in the previous image it would solve all the problems pretty easily.
  9. The problem is using bounds is axis aligned. If the segment is not travelling along the axis' then the bounds is not accurate.   See image below:   So the middle one, which is what Unity does with bounding boxes is wrong for what i need. And thats the problem i am having.   So i cannot accurately detect when a mouse ray hits the segment, or when it collides with another segment because the bounds are not tightly wrapped around the segment shape, does that make sense? How do i solve this problem, so it is more like the 3rd example in the image?
  10. Hi I have a setup of connected nodes via segments - these segments travel in any direction (think of like a connected road network). My problem is how to accurately do collision checks for these segments and nodes. Additionally some segments are curved via bezier curves which adds to the complexity of collision detection.  There are 2 types of issues i do not know how to solve: 1) User clicking with the mouse and detecting a node or a segment (for example adding a new road branching off an existing node or segment). Since adding a branch to a segment, would need to insert a new node and split the selected segment.  2) Detecting if a segment collides with another segment when trying to add a new one at run time. My code setup is: public struct Node { public Vector3 Position { private set; get; } //list of segments node is connected to public Segment?[] Connections_Segments { private set; get; } //max 4 size //list of nodes connected to - useful for pathfinder public Node?[] Connections_Nodes { private set; get; } //max 4 size //constructor etc etc } public struct Segment { public Node[] Nodes { private set; get; } //maximum of 2 nodes public int Thickness { set; get; } //thickness of the road i.e 2 lane, 4 lane etc public Vector3 AnchorPoint {private set; get; } //TODO bezier curve //constructor etc etc }  Some things i thought about and tried but didn't work: I added bounds to both nodes and segments, but soon realised this made no sense. In Unity bounds are axis aligned, this is no good for roads that do not follow along an axis (curved roads or roads going diagonally). I also thought about using quad tree which only makes sense if the roads are straight, but they are obviously curved. And again using bounds is axis aligned so it won't be able to accurate represent roads that do not follow an axis (such as curved segments and diagonal segments). So i am bit lost now what else to try. Hoping some one who has experience with design problems may have some suggestions that I can try.
  11.   You're right i am an idiot! I have solved it now i realised that mistake ! oops :P
  12. Hi    I have a line segment intersection method which i translated from JavaScript to C#. But it seems to be hit or miss on success rate on whether it detects an intersection of two lines. I don't know why this is. This is my method: public static bool LineSegementsIntersect(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, out Vector3 intersection) { intersection = Vector3.zero; float A1 = p1.z - p0.z; float B1 = p0.x - p1.x; float C1 = A1 * p0.x + B1 * p0.z; float A2 = p3.z - p2.z; float B2 = p2.x - p3.x; float C2 = A2 * p2.x + B2 * p2.z; float denominator = A1 * B2 - A2 * B1; if (Mathf.Approximately(denominator, 0)) { return false; } intersection = new Vector3((B2 * C1 - B1 * C2)/denominator,0f,(A1*C2 - A2*C1)/denominator); return true; } And my test data has:   if (Maths.LineSegementsIntersect(start,end, A.Position, B.Position, out intersectingPoint)) { Debug.Log(start+":"+end+" intersects "+A.Position+":"+B.Position+ " at: "+intersectingPoint); return true; } And my console gives me true for: This is clearly incorrect. Yet i get true and i have no idea why that is.
  13.   Oh so i test from the higher leaf downwards rather than the specific ones the area covers, that makes much more sense albeit slightly slower but it solves the issue! I'll work on it tomorrow! Thanks ! :)
  14.   Right, but then how do you search for such an object since as far as the search is concerned it doesn't find the object since its position is out of the boundary that i searched for. Either that or maybe my code is wrong ?
  15. Hi   I have a quad tree to make finding object collisions easier since my objects vary in sizes on my tiled map and the map is reasonably large. My problem is i think i might either have misunderstood quad trees, or, its not suitable for my needs.   So here is a visual demonstration of the issue i have: So the red square is some object in my quad tree, the blue dot represents its position.  The green shape is the area i am searching, since this is where i want to place my next object.  The problem is the area i search is just the green rectangle. And it won't detect the red object since it's position (the blue dot) is outside the range, even though visually we can see it is clearly colliding. But my quad tree search won't find any objects in the way and thus i  get no collision detection. So, am i misunderstanding how to use a quad tree, or am i using the wrong thing for what i am trying to do here?