New answers tagged

1

This depends on the language. Since you didn't mention language, I am for the moment going to assume either C++ or C# or D or Rust or some similar low-level language (not Java!), because game development. There are zero advantages to keeping x and y as members of Player rather than abstracting out to a Point/Location type. There are many many advantages to ...


0

Instead of (depricated) Application.Load(Application.loadedLevel); use SceneManager.LoadScene(sceneBuildIndex); or SceneManager.LoadScene(sceneName); You can also get current active Scenewith SceneManager.GetActiveScene().


2

Code should be like: void OnTriggerEnter(Collider other) { if(other.tag == "setting_object_tag") { Application.LoadLevel(Application.loadedLevel); } } Make the colliding object as trigger and not using gravity as it will not effect surroundings. Application.loadedLevel is the current scene.


1

I found the problem while modifying my code to try out Jon's sugestions. Somehow I added a max distance of 5 to the RayCast. Must have gotten confused with the many overloads or something. It works if I modify the second line like this: if (!Physics.Raycast (transform.position, new Vector3 (0, -50, 0), out hit/*, 5*/)) {


0

You are offsetting the model as well as scaling its x and z coordinates, which I assume is why this is failing for you. You really aren't providing enough information to help you more than that, since we don't know how your interface between the terrain and the rest of the game looks like. I'd assume that if you account for the offset and the scaling along ...


0

In addition to @lvictorino answer, maybe what you're looking for is in fact the AddForce method. I'm not exactly familiar on how it could work with Unity, but roughly, what you could do is // Rough pseudocode difference = touchPosition - objectPosition distance = difference.lenght direction = difference.normalize radiusForMaxForce = 50 // tweak this ...


0

I think that you have error in your collision testing function. Maybe it has to be like this: foreach (Rectangle wall in walls) { /* your code here */ } In your original code you are not testing all the walls from the list generated by getWalls() procedure.


2

First of all, all your physics related stuff should be done in FixedUpdate method and not in Update method. Update is called every frame, while FixedUpdate is called at fixed interval. When you ask Physics movement computation in FixedUpdate Unity will predict the new position in Update until it'll be able to compute the actual position in the next ...


1

As long as you have the position of the moving wall and the size of it, as well as the position of the player and the player size, it's easily doable without using a tile map :) I posted three guides based on shape collision, so check them out: For testing if a point is inside a polygon, use the code I posted below. I wrote this in C# based off of the ...


0

I wrote this in C#, but It has the same idea, and can be taken as pseudo code. Because in pong you're only dealing with rectangles and not polygons, it makes collision detection and response fairly easy. In C#, the .NET 4.5 framework already has a method at allows you to check if a rectangle is intersecting (touching) another rectangle. (Keep in mind that ...


1

As a general solution, a sphere collider can be imitated with this a simple 3D distance formula equation: Distance = sqrt((x_2 - x_1)**2 + (y_2 - y_1)**2 + (z_2 - z_1)**2) where x_1, y_1, and z_1 are the x, y, and z coordinates of center of the sphere and x_2, y_2, and z_2 are the x, y, and z coordinates of a given vertex. Using this idea, you could simply ...


0

Firstly, my Moving Boolean was a static variable(this was changed before I asked this question). Secondly, I failed to reference the object I was colliding with thus building on my first logic error of the static Boolean - which made all instances share the same value. Lastly, after realizing the later of the two and the fact that my code was not properly ...


0

Check out this source. I wrote the code below based off of it to make it more friendly for a C# application. This works with convex polygons as well which might be a little overkill for you, considering you only need rectangles, but it works none the less. I found more tutorials and explanations of why the separate axis theorem (which this uses) works, and ...


4

Physics done on the GPU are usually cosmetic effects. Particles are a good example, but hair and tall grass are similar. The GPU is very good at doing a massive number of calculations and since it also handles the drawing if these things it is a good match. A GPU isn't very fast at communicating the results back to the CPU. This is why physics used in ...


0

You are using absolute positions in world space to detect "in bounds" or "out of bounds" on a 2D xy axis plane. It would be easier and less code to do line intersect testing where each wall is two points connected by a line and your collision testing line intersections with your player line of motion. That line of motion can be current position and ...


0

In general, approach B is actually faster since it can be cached and vectoried more efficiently using Structs of Arrays (SoA) / Arrays of Structs of Arrays (AoSoA), which you probably should be using anyway.


2

I think you may be misunderstanding what the Equals() method does - it's checking whether the GameObject instance col.gameObject is equal to whatever you pass in as an argument. You're passing in a Boolean value, which is not a GameObject, so the result will always be false. I think you mean to write something more like this: void OnCollisionEnter2D(...


4

The way fighting games work is with attack and collision boxes per frame. This way there is not a high/mid/low hit per se, a high-kick could for example hit a jumping character. In Street Fighter this looks like this: The hit is scored if a red box hits a opponents blue box. Red being the attack box and blue hit boxes In your example each frame of ...


2

error: y has private access in Polygon This simply means, that the y field is private in the Polygon class. Instead of trying to use balls1.y to reach that variable, use setPosition(float x, float y), getX() and getY()


0

My approach was fundamentally flawed. After chancing upon this post I realized that using only a single point and some weird rounding would not work. So, I decided to add four collision points on all four corners of the player. So, I replaced my collision detection code for something that compensates for this. typedef struct tagPlayer { POINT pos; ...


0

Engines aside, circle collision is incredibly easy to program - you can do it from scratch. Every circle object must have a Vec2d position value and a radius. In your update loop, iterate through your list of all circles and then test to see if any pos value of one, >= the pos of any other, + both radiai. If this is true, stop the gravity force from acting ...


0

Looking at your responses to the two answer here so far, I don't think you're going to find a solution that works the way you want it to without it being some level of hacky because you're not using objects. The actual picture tiles do not have any properties support in Tiled. The only thing that has support for properties are the layers and objects. The ...


0

The dot product has two nice properties for collision avoidance. The dot product is closely related to the cosine of the angle between two vectors. The dot product of a unit vector A and a second vector B of any non-zero length, the result is the length of vector A projected in the direction of vector B. So as you can see in the image; if the angle is ...


1

In unity when collision don't work you can fix the problem by following the below steps: 1.Set Collision and Triggers based on game(If game was 2d you should use BoxCollider2D) and check BoxCollider2D trigger Boolean. 2.you should check Rigidbody Component that attached to objects because Collision need physics component(if game was 2d you should use ...


0

I had the same issue when i was making a breakout game it seems that Kinematic rigidbody collider don't interact with static ones you can check the table here: https://docs.unity3d.com/Manual/CollidersOverview.html. for me i've overcame the issue by disabling isKinematic and setting the GravityScale to 0. you can either do that or use a script to limit the ...


0

Use transform.Translate(dir * Time.deltaTime * snakeSpeed); instead of transform.Translate(dir); on Move() method. Keep a float variable called snakeSpeed. But you should not work with translation of a rigidbody. Use velocity instead. Code should be like: [SerializeField] private float snakeSpeed = 10f; private Rigidbody2D snakeHead; void Start() { ...


0

You have to be prepared to avoid collision when the player is in dodging state even it it's not in collision / OnCollision(). Put a block like below on the Update(): if (isDodging) { Physics.IgnoreCollision(GameObject.FindWithTag("Enemy").GetComponent<Collider>(), GetComponent<Collider>(), ...


0

I would suggest calculating you distance from plane first; and then when the distance <= to the radius carry out the collision reaction. You can then alter this to calculate distance and if the distance is less that radius( which mean the object is overlapping) shift the balls position and then carry out the collision reaction.


0

There is an isometric plugin for phaser with physics capabilities that can help you with collisions. Here's the link: http://rotates.org/phaser/iso/ Check out their physics sample.


0

Even if you don't use XNA or Unity, you could still use a C# physics engine, for instance Farseer Physics (a port of Box2D with additional features) You could also code your own physics from scratch, but I wouldn't recommend it unless you have a really good reason to do so. I did it on a project as I wanted some specific behaviour on some collisions, but it'...


0

I've used the separating axis theorem and I've come up with this huge code: this.checkCollision = function(entity1, entity2) { var width1 = (entity1.width * this.COLLISION_EPSILON_WIDTH)/2; var height1 = (entity1.height * this.COLLISION_EPSILON_HEIGHT)/2; var width2 = (entity2.width * this.COLLISION_EPSILON_WIDTH)/2; var height2 = (entity2.height * ...


0

Assuming you're trying to coordinate the Start() method of various scripts, you can ensure they execute in the order you want by going into the menu at Edit > Project Settings > Script Execution Order. Just make sure your box collider script is running before the raycast script and you should be good to go! From Unity's official documentation: ...


-1

The best way in my opinion would to integrate Box2d. Here is the download : https://github.com/erincatto/Box2D ; And here is a tutorial on how to integrate it with OpenGL (he uses SDL for window handling) : https://www.youtube.com/watch?v=kEClRFKyGkw&index=53&list=PLSPw4ASQYyymu3PfG9gxywSPghnSMiOAW


0

First thing to consider: You have your giant world broken up into manageable regions. So why not break up a region into more manageable pieces, like sub-regions? By doing this you can further break-down the total # of objects to check for collision detection. But this is just a side note. Now, here is where you can achieve very quick collision checking for ...


0

I'm not entirely sure why you're checking each enemy for collisions if you're only worried about collisions with the player. If the player can only ever collide with enemies, then if you only check the player for collisions with enemies rather than all the enemies for collisions with the player, you would go from 25,000 enemies x 60fps = 1,500,000 checks per ...


1

The simplest way I could think of is to use a grid (2D if your enemies can only move on the xz plane and 3D if they can move up and down too). You will have to hold an additional reference to the grid cell inside your enemy objects, and also in the player object. This way, you will still have to iterate over all enemies in your map, but only check collisions ...



Top 50 recent answers are included