Tag Info

Hot answers tagged

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 ...


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: ...


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. ...


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 ...


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 ...


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 ...


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 ...


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 to ...


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.


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 ...


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 ...


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 ...


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 + ...


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 ...


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 ...


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 ...


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.



Only top voted, non community-wiki answers of a minimum length are eligible