New answers tagged

0

You are not using collisionBitMask The class reference can be found Here A example of code is Here which also explains very well how collisionBitMask works


1

Check broad-phase collision detection. Example link That would reduce the collision detection cost. Then figure out WHAT causes your performance drop. Virtual method calls themselves are not that expensive - 1000 of them in a frame will definitely NOT cause a slideshow. Perhaps the message system is slow? The message creation copies data by value? etc etc. ...


0

Try Using NSUserDefaults it has the full CRUD functionality and you can save each ship type with their specific hit points and cannonball More description about NSUserDefaults is Here


0

You are removing their children which they don't have and to remove them you have to remove them from Parent. You can find more about children and parent Here func CollisionWithRed (Orange: SKSpriteNode, Red:SKShapeNode){ Orange.removeFromParent() Red.removeFromParent() }


0

I know, it's a bit late but try boundingSphere.Center += entityPosition; before you return your sphere in CreateBoundingSphereForModel


0

The box collider on the parent object is marked as "is Trigger". Maybe your code for the collision detection for this collider is causing the player to die when colliding with the parent object.


0

Yes, it is collision checking. Though, there's a little misunderstanding about variables that I'll first try to clarify before proceeding to a solution to your problem. What does what First of all, image_number is a constant (YoYo Docs call it read-only variable) that gives you the number of sub-images of an object's current sprite (its sprite_index). If ...


0

Organise your units in areas. An area can be a section in your grid (1 There are various implementations of quadtrees (Google is your friend). This way a unit only has to iterate through the enemy units that are in neighboring quadtree spaces (or quadtree spaces within range of said unit). This greatly speeds up the targetting/moving scenario's as each ...


1

If you want to just have one GameObject for your character, you cannot add multiple Colliders of the same type to your GameObject and still have the ability to access all of them in your scripts (only the first in order of components would be accessible). However, you CAN add multiple Colliders of DIFFERENT types while still maintaining accessibility. In ...


0

Another option would be to use animation curves. You can learn more about them here, as I am not entirely familiar with them.


0

The onTriggerEnter has a typo and it will be OnTriggerEnter. The OnTriggerEnter is invoked whenever there will be a collision between a trigger and a rigidbody. Thus the Collider object will be referenced by the trigger and hence the defined action would be performed as of the function definition by the OP.


0

What you need to do is to calculate the normal of the collision then reflect the impact vel across the collision normal: // r = v - 2 * dot(v, n) * n; r = result vel, v = impact vel, n = normal of collision.


0

Have you considered making an array of those PictureBox-es? But, to set the array one by one to an existing object is a pain for sure. You might want to initialize those objects by code. This might help If you see in those example codes: Dim x(10) As widget // x now contains 11 elements of type widget, x(0) through x(10). That is how you initialize an ...


0

well i fixed it. lol well the reason it wasn't working right was because i used translate on another part of the script to move the whole ship on a rail while this part moves side to side. so these few line of code weren't the problem at all. guess that's what i get for trying to be secretive and hiding code. MovePosition works fine with collision. but still ...


0

My apologies if I'm wrong but.. Dude, drop that script and take a look at the tutorials, specially -Roll a Ball- and SpaceShooter You're not checking for collisions you just posted the same code twice. The code for move your object have not sense: You're not applying forces or transforms. You're just adding and subtracting your current position to that ...


0

You just need to compare sidelines. These are the algebraic representations of vertical or horizontal lines. Note, this will return only the current value, not what will be, but from here is only one step to do that. Let's define a Rectangle with the following properties: Rectangle.x1: rectangle's left side line (this is a vertical line) Rectangle.x2: ...


1

I'd like to point you to the work of J. van de Berg et al. on Optimal Reciprocal Collision Avoidance. http://gamma.cs.unc.edu/ORCA/ In their paper, they provide the mathematics and algorithm outline on how to solve the problem you state in an optimal way using randomized linear programming. Best of luck :).


0

It is because your "Ball b" and your ball's collider "Rectangle ball" know nothing about each other. When you update the ball's position with b.update() the rectangle ball stays put. I would make the Rectangle be a member variable of the Ball class and update its position every time the ball's position updates. i.e. if(goal.contains(b.getCollider())


1

I don't think there's an efficient way of solving the problem exactly, but here's how I'd try to tackle it. First, I'd use bounding volumes around each object, instead of the objects themselves. Each object can be approximated by the union of more than one bounding volume, though. The simplest solution would be to compute a single bounding volume that ...


0

There are two ways to address this question that I can see. First, if you simply want to find a way to steer, then you just need to implement pathfinding (I find this quite helpful). That would be the end of that (and is the correct practical answer to this question), but I think you are more curious about a mathematical solution to your problem. To address ...


0

When you have a collision, do a CircleCast (or BoxCast, depending on the shape of the collider of the colliding object) from the center of the colliding object with a size equal to its own collider, a distance of 0 and a layerMask setting which only covers the polygon collider. The resulting RaycastHit2d object will tell you the closest point of the polygon ...


1

I've been thinking about this problem for a long time and looked at some of the answers here and on other forums. I came up with the following idea: Suppose the circle has radius R. When looking at cases where the circle collides with the AABB , the center of the circle has to fall within a certain area around the AABB. The extreme cases are when the center ...


0

Minimal runnable example Two spheres falling on different points of a plane at different heights. Since they start at different heights, they will hit the ground at different times. We detect the ground hit, and print out which sphere touched the ground when. Gnuplot visualization of stdout: See how: when one sphere hits the ground, the pink square ...


0

Nevermind, I found out how to solve it: I should use BoundingBox.CreateFromPointsinstead of the standard constructor. The standard constructor gets confused if Minand Max aren't actually Min and Max. BoundingBox.CreateFromPoints takes care of this.


0

I recommend you look into how box2D works. Anyways use one of the below, most likely BeginContact. void BeginContact(b2Contact* contact); void EndContact(b2Contact* contact); Excerpt from the from the greatest source of Box2d knowledge know to mankind to explain why. iforce2d.com: Anatomy of a collision Impact 1, 2, 3 When fixtures are ...


-1

Option (C): change the screen resolution back to 800x600. Even if you don't do this, consider it as a thought experiment. In that case, it's the responsibility of the display to resize the graphics to fit its physical size, and then the responsibility of the operating system to give you pointer events at an 800x600 resolution. I think it all depends on ...


0

ClassicThunder's answer is correct, but I'd like to provide an example of an alternative/simpler means of achieving the desired effect. This is a simpler solution for rapid prototyping, cases where you don'thave access to a fully featured library, or for cases where you don't have access to a GPU (e.g. in embedded systems). To perform said mapping, you can ...


2

Another option would be: On each input mouse movement event, move the in-game mouse cursor by the number of game pixels corresponding to the number of pixels in the mouse event. This comes naturally for 3D games that lock the real mouse pointer to the center and rotate the aim direction by an amount corresponding to the input mouse movement, but you could do ...


0

Continuous Collision Detection (CCD) and Ray Casting provide a specific time of impact (TOI). However using two AABBs and two triangles to create the 'hexagon' that covers all locations of the AABB's travel, you would only know whether TRUE/FALSE an intersection occurred - this isn't as useful when dealing with 'swept AABB' detection. Even with the images ...


39

Typically (even for 2d games) there is a separate coordinate system for the game that is independent of the resolution, this is typically referred to as the world space. This allows you to scale to an arbitrary resolution. The easiest way to achieve this is use a 2D Camera, which is essentially a matrix that defines the transition from world space (your ...


-2

You can use a coroutines for this task, you should call this coroutine in order to damage you player, so you can set a time of invencibility with the waitForSeconds(3f); function bool finishedCoroutine = true; void OnTriggerEnter2D (Collider2D other) { if (other.gameObject.tag == ("Damage")) { { if(finishedCoroutine){ ...


0

I solved the problem myself! I now create the CollisionShape before applying the transformation. For transforming the RigidBody correctly, I extract the sacling-value from the matrix and give it to _rigidBody->getCollisionShape()->setLocalScaling. I then remove the scaling from the matrix and give that to the setWorldTransform. Here's my code: float ...


3

According to the Unity documentation for OnTriggerEnter2D the trigger is "[s]ent when another object enters a trigger collider attached to this object (2D physics only)". The function should only be called once per entrance. You could gather further data by logging the number of calls to OnTriggerEnter2D and OnTriggerExit2D. Perhaps some funny business is ...


-2

Use a bool variable to make sure you only enter the if once, then reset it after you have left the trigger. Or dont reset it if it has to happen exactly once. void OnTriggerEnter2D (Collider2D other) { if (other.gameObject.tag == ("Damage")&&!isDamaged) { currentHealth = -5f; ...


-2

Create a collection and store a reference of the GameObject once it enters and remove the reference once it exits. For example, here I am utilizing HashSet. using System.Collections.Generic; private HashSet<GameObject> takenDamageFrom = new HashSet<GameObject>(); void OnTriggerEnter2D(Collider2D other) { // If damager and not yet damaged ...



Top 50 recent answers are included