Tag Info

New answers tagged

0

Take a Look at Texture2D.GetPixel You can find the contact point on the collider and then map that to the specific point on the texture.


1

This is how I'd do it: Generate convex hull from all planes Note: this includes both light frustum and scene AABB planes, so there should be a total of 12 planes Note: make sure all planes have matching orientation (normal outwards or inwards - doesn't matter much but it has to be consistent across all data and functions) Intersect every three planes ...


0

For many collisions, there will be several contacts to resolve. This is why you're getting multiple calls to your player.destroy(). I don't know what you're doing in the destroy method, but you shouldn't destroy any Box2D bodies of fixtures in there, as they might be needed for other preSolve calls. What you could do is instead of immediately destroying ...


0

Firstly, your question is very unclear. It doesn't have all the necessary information. Nothing at all in fact. Try to be a little more informative or precise in the future. When two bodies collide in Box2D there are numerous collisions. Collisions in Box2D are really the fixtures which are used to detect when a collision occurs. Collisions can happen in ...


0

Didn't realize it was as simple as just adding to the if statement. I thought I had already tried that. func didBeginContact(contact: SKPhysicsContact) { var firstBody: SKPhysicsBody var secondBody: SKPhysicsBody if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask { firstBody = contact.bodyA secondBody = ...


0

Swept object collision detection can be challenging but there are some common solutions. One way is when testing two objects, using the concept of relativity you can set up the math such that one object gains the motion of the other, so that its moving object vs a static object test. Another way is if you use something like MPR or GJK to do collision ...


0

I'll try a semplified answer. Assuming you store previous frame time and position (and rotation) calculate point X interpolte dT = frameTime * FrameDistance/(X-PositionC1atFrameA) Check position of other circle C2 at dT (check if it intersect C1) Calculate Rot C1 and Rot C2 at dt finaly apply your logic (points 2,3,4)


1

The solution was a lot simpler than the other things I was thinking of. I store all CollisionPairs in a separate collection and iterate over that collection. This allows me to do what I was doing before with partitioning, setting a boolean for the CollisionPair to true to represent that the involved bodies are in the same partition.


0

A common way to solve this is to have the concept of "islands" which are just groups of objects that might collide with each other. Objects from different islands are guaranteed to be far enough away that they can never collide. Objects can change islands as they move around and islands can join and separate. Even though this is a common technique, its ...


0

(i just want to feel like i am helping a game developer) From my little knowledge in game development i think they are actually intercepting but not appearing as such, you see you have a rectangle ship-in respect to its bounds ________________ | | | | | ship one | // your rectangle shaped ship in layout | ...


3

Fun fact: I used to work for the company that made Pac-Man. Anyway... how are you storing the wall data for your maze? Are you using a tile map? (Relevant: Wikipedia entry on tile maps). If not, you should consider it because one of the biggest benefits to using one is the ability to detect walls purely by looking at the contents of (x, y) in the array ...


7

Lets start with general rule of optimizing things, especially when it comes to games: Profile it. It's not worth working on something that works already, because especially with games, you will get stuck optimizing and refactoring what you have, instead of doing actual work. When a player is playing a game, they usually are doing just that, because a game ...


3

You've written your OnCollisionEnter2D function inside your Update function. You want it written after it: function Update() { // Your update code goes here. } function OnCollisionEnter2D(collision : Collision2D) { // Your collision response code goes here. } Also note that if you've marked the collider as a trigger, then it will never call ...


0

In your update loop: You first handle the input from the user and move him accordingly. Then, you check for collisions with the walls and identify which wall/walls collide with the player. To improve the efficiency of that, instead of checking every single wall in your game, you can check only the walls close to your player and check if there is a ...


1

You need to create two empty child GameObjects of material C that work in different layers. One child has a sphere collider with a radius of e.g. 5, reacting to colliders in the layer "One" and one child using a sphere collider with the radius of 10 working in layer "Two". The colliders that react only to the collider with the radius 5 just only react to the ...


2

Checking all the voxels should not be that bad - modern CPUs can often do brute force processing faster than 'clever' solutions because those clever solutions often contain a lot of branching and jumping around in memory which is very costly compared to simple arithmetic or iterating over an array. If youre using a low level enough language, you can try ...


0

Since you mention onCollisionEnter, could it be a typo? because, the function is written OnCollisionEnter (upper case O)


1

I'm sorry for answering my own question: I figured it out and it was just a matter of correct visualization. The inside-triangle check only works if the sphere meets the triangle head-on: in other words, the point of tangency between the sphere and the plane occurs exactly at the correct time. In the other case, if the sphere passes by the triangle such that ...


5

Step 1 - Don't check collisions in each key, test them at the end In your example, you are checking collisions for each key independantly. This will cause some trouble and code replication. In order to avoid that, I would suggest you use temporary variables that will stock the movement, increment it for each key and test collisions only once at the end: ...


0

Of course you can check the syntax automatically using an IDE like Visual Studio. However, without some more work the only measure of correctness is "does it do what you expect?" If it doesn't, then you would debug to find out why. Of course, you can take it a step further and apply Unit Testing. This is where you write code that sets up scenarios where you ...


1

Libgdx does not handle this itself, you need to take care about collision detection + collision response yourself. One possible solution would be Box2D, a 2D physic engine. It takes care about forces, mass, friction and other physical things. It also detects and handles collisions for you. It is also possible to let Box2D just detect the collision and notify ...


0

I wrote some articles on this awhile back. There are lots of different solutions to this problem, and the best answer depends on what sort of data you are using. A good general purpose solution is to use Zomorodian and Edelsbrunner's collision detection algorithm, which I implemented here: https://github.com/mikolalysenko/box-intersect You can read ...


0

You've made an infinite loop: def nextStageCollision(self): for tile in self.nextStageCollision(): You probably meant something like: def nextStageCollision(self): for tile in self.tileList: Note what you are iterating over. You are calling the nextStageCollision to find what to iterate over, which calls nextStageCollision to find what to ...


1

In your collision function, instead of returning a boolean, return a string so that you can detect each face: function colCheck(args) { if(obj2.y > obj1.y + obj1.height) { return "u" } if(obj2.y + obj2.height < obj1.y) { return "d" } if(obj2.x > obj1.x + obj1.width) { return "r" } if(obj2.x + ...


0

The simplest answer will be: Use 3D Colliders It's possible to freeze one of the axes (z-axis) when the grenade is bouncing back from a 3D Collider, hence it will only moves in x-axis and y-axis. Apply a sphere collider and rigidbody(with z-axis frozen) on the grenade, a cube collider with thin z-scale on the roof, when the grenade is thrown to the roof, ...


1

Try putting -speed when doing a left or up movement and speed when doing a down or right movement: tryMove: function() { var game = roguelike.game; var speed = game.library.speedPerSecond(this.speed); //Left if(this.moving.left && !this.collision(-speed, 0)) { this.x -= speed; } //Up if(this.moving.up ...


0

I guess terrain is 2d from the picture. If it is terrain the {x} axis distance between every vert should be constant. I also condider both players are grounded. Now lets have such varriables: Player 1 : p1where we have p1.x and p2.x Player 2 : p2 same as player 1 Let's also say player p1 is before p2 in other words he is behind him vert array: V with ...


4

Instead of testing the collisions ON the player, you should testing them AHEAD, to check whether there's a wall where the player WILL be walking. To do that, you'll only need to change 2 things: 1- Your player.collision function should accept two arguments: an x and y offset. You should add them to your collision checking algoythm too. 2- When calling ...


0

You are setting the position which doesn't allow box2D to act on the bodies the way you are intending. Set the velocity instead.


1

In your Map class, you are instanciating a Peter object on creation on line 25: Peter peter = new Peter(); In your Peter class, you are instanciating a Map object on creation on line 12: Map map = new Map(); So, when you create on of the two objects, it will start creating an infinite amount of maps and Peters (probably not what you want). This is a ...


4

So what you want is like this? As Stephan says, you have the right idea, just repeat it until you're all out of movement. 1. Measure length to next vertex along first slope. while( impending movement vector > length to next vertex ) { 2. Subtract length from impending movement vector. 3. Position impending movement vector at vertex... 1. ...


1

You are describing the proper algorithm. If you loop while you have remaining movement left, it wont matter how many segments you have to cross over. All of the calculations you describe are O(1) calculations so performance isn't an issue. Keep in mind that all terrain is triangles under the hood, so Trig and/or Dot Products may possibly offer some ...


0

Since you seem to be just starting out, I'll give you the simplest approach. First, define rectangles for all of your game objects (including your player) which will serve as their collision bounds. Once you've done that you will need a method that tests for collision between 2 rectangles (if you used the LibGdx rectangles then you can simply call their ...


1

In the third iteration of the loop, pmx-i is equal to -1, map.FALL[-1] is undefined and undefined[pmy-1] is an error since you can't access an index of undefined.



Top 50 recent answers are included