Menu
  • HOME
  • TAGS

how to Detect Collision and Remove body and image after Collision

java,android,collision-detection,andengine,game-physics

You should create a new "ContactListener" and bind it to your "PhysicsWorld" By "physicsWorldInstance.setContactListener(...)" and in the ContactListener override "beginContact". for example: public void beginContact(Contact contact) { final Fixture x1 = contact.getFixtureA(); final Fixture x2 = contact.getFixtureB(); if (x2.getBody().getUserData().equals("player")&&x1.getBody().getUserData().equals("monster")) { Log.d("TAG", "Collisoion"); } } ...

Is smooth slow motion physics possible with SpriteKit?

animation,sprite-kit,game-physics

The simple solution (provided that this behavior is normal and not caused by, for instance, updating the ball's position manually or via a move action) would be to design the game/physics so speed 1.0 represents the slowest game speed, while at "normal" speed the speed property might be, say, 4.0.

How to know whether an SKSpriteNode is not in motion or stopped?

ios,objective-c,sprite-kit,game-physics,skspritenode

Since you are using physics you can use the resting property of SKPhysicsBody. if sprite.physicsBody?.resting == true { println("The sprite is resting") } else { println("The sprite is moving") } Hope this helps....

De-Activate Physics on SpriteKit

android,ios,objective-c,sprite-kit,game-physics

Just set the physicsBody property of the SKSpriteNode to nil. If you later need to apply physics again, just assign another physicsBody.

Getting a turret to turn until facing a target direction?

math,vector,box2d,game-physics,trigonometry

First off, you should take the angle of the target relative to the turret, not the other way around. This can be fixed by swapping the position vectors in the subtraction. Second, once you have the target angle, subtracting the turret's current angle will give you the rotation offset you...

How do I move a Rigidbody towards target without adding force or velocity?

c#,unity3d,game-physics

If I understand you correctly, you are looking to change the direction, but not the magnitude of your velocity vector. You can get the current magnitude in 3 dimensions using: double magnitude = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y,2) + Math.Pow(z, 2)); you can then just multiply a unit vector that points...

Arduino Esplora Pong Game

c,arduino,game-physics,pong

So following @PaulOgilvie's idea I fixed the problem with the following code: if (BPY >= 160 || BPY <= 0) {//Goal Detection if (BPY >= 160) { playerScore = playerScore + 1; } else { computerScore = computerScore + 1; } DrawCourt(0); EsploraTFT.fillCircle(BPX, BPY, 7, ST7735_BLACK); EsploraTFT.fillRect(computerPaddle, 154, 32, 3,...

Get 3d object boundaries

opengl,3d,game-physics

This is how you can compute the minimum and maximum (bounding box) of a 3D object. void BBox(GLpoint *p, int n_vert, GLpoint& p_max, GLpoint& p_min) { p_min.x = p[0].x; p_min.y = p[0].y; p_min.z = p[0].z; p_max.x = p[0].x; p_max.y = p[0].y; p_max.z = p[0].z; for (int i=1; i<n_vert; i++) {...

Box2d Body to follow mouse movement

libgdx,box2d,game-physics

The skew looks like a problem with aspect correction, try, camera = OrthographicCamera(200, 100 * (w / h)); or even, camera = OrthographicCamera(200, 100); To get the end of the box to follow the mouse as in the picture just redefine the box, shape.setAsBox(5, 2, Vector2(offset, 0), 0); ...

Large-scale spherical world in a physics engine

game-physics,physics-engine,cannon.js

If you go the sphere/cube path, you get many things "for free" from the physics engine. It includes stable contacts, friction, collision events etc.. If you implement a "force sphere" that applies force in the normal direction on each penetrating vertex, there are a few obvious things that you will...

how to find slope of a 3D plane

opengl,graphics,3d,game-physics

Turn the rectangles into triangles. That will make many things more simple since the rectangles in your example probably aren't planar. Select two sides of the triangle and create two vectors which point along those sides (i.e. v1 = p2 - p1 and v2 = p3 - p1). To get...

How do i detect collision betwen two animated balls?

javascript,for-loop,collision-detection,game-physics

Your conditional should look like: var distanceFromCenters = Math.sqrt(Math.pow(Math.abs(fiender[j].x - kuler[i].x),2) + Math.pow(Math.abs(fiender[j].y - kuler[i].y),2 ); if (distanceFromCenters <= (fiender[j].r + kuler[i].r)) { // you have a collision ...

How can I determine the position of a body in 2D space after a given time?

c++,math,physics,game-physics,orbital-mechanics

You're probably looking for Newton's Law of Universal Gravitation. Gm1m2 / r2 = F Once you find F you can just use it in a standard equation of motion: Fyt2 / 2 + vyt + y0 = y Fxt2 / 2 + vxt + x0 = x ...

Accurate Circular Orbit Equation in java

java,2d,game-physics,gravity,orbital-mechanics

The following code fixed my issue. I was overcomplicating my math equations as I usually do. Took me three weeks of Googling, asking people with degrees in physics and mathematics, and reading Javadocs before I figured that one out. Turns out how atan2 works is simply different from how I...

How to add torque to a rigidbody until it's angular velocity is 0?

unity3d,game-physics

Note: I wrote this before looking up the different ForceModes, but all of the advice still stands. Your freeze was because you were asking for too much precision (you're subtracting from velocity by the same amount repeatedly, with no consideration for overstepping (.5 -1 is never 0) or direction (your...

Obj-C and SpriteKit - Changing a sprite value that is created randomly

objective-c,random,sprite-kit,game-physics,sprite

Sorry in advance for any english mistakes, as I'm not an native english speaker. From your question I understand that the reason you are keeping a reference to the drop (self.drop) is to check what is its colour when it hits the ground. So you could just delete that, and...

addAction always rotates the actor origin 0,0, why?

java,android,libgdx,game-physics

you're rotating the group not the actor so try this set the origin of the group to group.setOrigin(group.getWidth()/2, group.getHeight()/2);

I have an array of blasts and an array of zombies, how can I efficiently detect collisions?

libgdx,game-physics

You need to put the other iterator inside of the other iterator, try this: Iterator<Rectangle> zombieIter = zombies.iterator(); while(zombieIter.hasNext()) { Rectangle zombie = zombieIter.next(); zombie.x -= 150 * Gdx.graphics.getDeltaTime(); Iterator<Rectangle> blastIter = blasts.iterator(); while(blastIter.hasNext()) { Rectangle blast = blastIter.next(); blast.x += 200 * Gdx.graphics.getDeltaTime(); if(blast.x + 16 > 800) blastIter.remove();...

Android libgdx bouncy screen bounds

android,libgdx,game-physics,bounce

Check for the collisions with the walls. I'm assuming you're rendering Bitmaps, so the origin of the square we'll say is the top left corner. In that case: if (x + width >= SCREEN_WIDTH || x <= 0) vx *= -1; if (y + height >= SCREEN_HEIGHT || y <=...

Point adding mechanism troubles?

java,android,game-physics

I need an answer so I can format using monospaced. Does the rectangle have an exit that must be met by the ball - so it passes through? -------------- +--+ | | o | | +--+ t0 -------------- +--+ | | o | | +--+ t1 -------------- The ball path...

Problems with render in a game developing in Java

java,game-physics

Add a small delay between render/update cycles to give the cpu time to deal with what you're trying to do, use sometng go like Thread.sleep(40) (25fps)..assuming there's a update loop in there somewhere... Also take a look at BufferStrategy JavaDocs, which has a simple example of how you should use...

Acess normal force/impulse between rigid bodies

unity3d,game-physics

You might need to know some physics equation or principle: i.e. 1/2 mv^2 the Kinetic energy of your stone. To make it simple: <Kinetic energy before collision> = <Kinetic energy after collision> + energy accepted by the wall. Hope it would help u....

SpriteKit SKPhysicsBody bodyWithTexture is Upside Down

ios,objective-c,sprite-kit,game-physics,skphysicsbody

The solution was to hold a strong reference to the atlas instead of the textures themselves. This also simplified my code sine I'm already preloading all my atlases with [SKTextureAtlas preloadTextureAtlases:textureAtlases withCompletionHandler:^{ ... }]; at the beginning of my scene. This seems to use the same amount of memory (if...

Spritekit - How to create a hole like billiard's pockets?

ios,swift,sprite-kit,game-physics

What I would do in this circumstance is create a SKSpriteNode for the hole, with just a black image as the circle. Then when the two nodes collide, you delete the ball node. I'm assuming you are doing this in your GameScene by the way First, create an enum for...

Date getTime gives low values for longer durations

javascript,game-physics,craftyjs

I've seen something wrong in your code: - on keydown you are calculating and recalculating the Date.now() so just changed this part of the code keyboard[code.keyCode] = true; var then = new Date(); keystart[code.keyCode] = then; with this: var then = new Date(); if(!keyboard[code.keyCode]) { //only if not yet pressed...

Movement of sprite using fixed time step

c++,game-engine,game-physics,sfml,movement

object.speed = object.speed * TimePerFrame.asSeconds(); This line is reducing the speed every frame until it is 0. You need to scale the movement distance by delta time whenever you move the object. Try this: float distance = speed * TimePerFrame.asSeconds(); sprite.move(cos(sprite.getRotation()*PI / 180) * distance, sin(sprite.getRotation()*PI / 180) * distance);...

swift: sprite kit collisions and bitmask not detected

ios,swift,sprite-kit,game-physics,skphysicsbody

For Problem 1: your line physics body has a size of 0. You have to create at least a small rectangle which represents the line. Otherwize there is no collision. For Problem 2: func didBeginContact(contact: SKPhysicsContact) { println("contact \(++tempCounter)") println("bitmask1: \(contact.bodyA.categoryBitMask)") println("bitmask2: \(contact.bodyA.categoryBitMask)") } There's a typo. You must use...

Apply Physics2D to 3D Game Objects - Unity3D

unity3d,2d,game-physics,unity3d-2dtools

It is not, however what you can do with rigidbody3d is lock the physics movement and rotation on it. For example, if you only ever wanted it to move along the x and y axis of your game, in the inspector just tick the freeze z movement box for the...

Set the maximum and current speed of a car in Phaser

javascript,game-physics,phaser-framework,racing

The reason it stops dead is because you're moving it with velocity, not acceleration - and are setting velocity to zero in your update loop (this effectively says "stop, now!"). Remove those lines and in your call to velocityFromAngle you should feed that into body.acceleration instead of body.velocity. Here is...

Getting distance between point of an object and another object

c#,unity3d,game-physics

I'm not exactly sure what you wan't to achieve... If you wan't to get potential objects at 0.5, 1, 1.5, etc. on lets say the Z Axis you probably would want to do this with raycasting. If you wish to check for any objects returning the direction dependant to the...

Why won't my ball bounce off a block?

math,processing,collision,game-physics

You're initial set up is actually almost perfect. I only changed 2 things in the the third if statement (the if statement which handles the collision with the rectangle). -Added/subtracted the width/height of the dot to the x/y of the dot. Because of this you will not just use the...

In Box2D, a Body that causes player to bounce, but object does not bounce itself

box2d,game-physics

Used this in the end .. public void preSolve(Contact contact, Manifold oldManifold) { if (contact.getFixtureA().getBody().getUserData() instanceof Spring){ float impulse = contact.getFixtureB().getBody().getMass() * impulseToApply; contact.getFixtureB().getBody().applyLinearImpulse( new Vec2(0, impulse), contact.getFixtureB().getBody().getWorldCenter() ); }else if (contact.getFixtureB().getBody().getUserData() instanceof Spring){ float impulse = contact.getFixtureA().getBody().getMass() * impulseToApply;...

How to get exact height and Width of PhysicsWorld in Meters?

java,android,box2d,andengine,game-physics

I solved it in my way.. thank you @LearnCocos2D. this.mScene = new Scene(); this.mScene.setBackground(new Background(0, 0, 0)); this.mScene.setOnSceneTouchListener(this); this.mScene.setOnAreaTouchListener(this); this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, 10), false); this.mScene.registerUpdateHandler(this.mPhysicsWorld); final Rectangle ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2, vertexBufferObjectManager); final Rectangle left = new Rectangle(0, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager); final...

moving physics body at a constant speed

game-physics,rigid-bodies

Constant speed can only be achieved in a universe with no other matter. So, you've got to remove friction(no air to bump into), gravity(no other mass pulling on the object to speed it up or slow it down), etc. It'll look very strange if those effects apply to every other...

Why should the mass of one object never be 100 times more than another?

unity3d,game-physics,physx

There is not one with the information you have given. Have you ever collided with a bug while driving? Was there some catastrophe, when it happened? If we are placing value judgements on physical phenomenon, then it would probably be "bad" from the bug's point of view....

Restricting movement of box2d body along an axis in andEngine

box2d,andengine,accelerometer,game-physics

I solved the problem by changing the type of box2d body from dynamic to kinematic, read about body types from here, and found that in my case kinematic body was better as a dynamic body it was getting affected by all the forces in physical world. ballBody = PhysicsFactory.createCircleBody(this.mPhysicsWorld, ball,...

Java 2D Platformer Gravity

java,game-physics

I would probably use something like the following. if(collisionDown == false) { characterYnext = characterY + fall; //Get Next Position if(NextMovementCollides()){ //Basically if next position is too far. characterYnext += difference_between(CharacterY,Ground); //This should move the character to the ground state. fall = 0; //No longer falling so reset the value....

Andengine - RevoluteJointDef torque

andengine,game-physics,revolute-joints

I think this page has the example code what you need from andengine examples. https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/PhysicsRevoluteJointExample.java This should help!...

How to shoot “bullets” in java swing animation game [closed]

java,swing,animation,graphics,game-physics

Basically, what you are going to want to do is create a new class for Bullet. This class will hold the data values for each individual bullet (x position, y position, x velocity, y velocity). Then, create a list of bullets in your main class. Whenever you want to add...

Swift Spritekit Contact Bitmask and Score Label

ios,swift,sprite-kit,game-physics,bitmask

You have to test if the colliding bodies have the correct bitmasks before increasing the score inside didBeginContact. You can use the following code to increase score on collision between paddle and ball. func addScore() { score += 1 scoreLabel.text = "\(score)" } func didBeginContact(contact: SKPhysicsContact) { var body1 :...

Keep object the right way up on the surface of a planet

c++,box2d,game-physics

There is an easier way. I am assuming that by "right way up" you mean that the feet should always point to the planet. Do the following: Place an additional circular body at the same position as your planet (basically a small circle that is "inside" your planet). That body...

If hitTestObject = true return current position on screen?

actionscript-3,collision-detection,game-physics,flashdevelop

If you don't want fireboy1 to go past the basePlatform, you should probably do something like: fireboy1.y = basePlatform.y - fireboy1.height Please note that this all depends on both fireboy1 and basePlatform having top-left orientation....

Libgdx - difference between Box2DDebugRenderer.render and spritebatch.draw

android,libgdx,game-physics

The difference is very simple. The Box2dDebugRenderer is extremely simple to use. It basically requires just a single line of code (the one you already wrote in your question), and it will render simple shapes to visualize your Box2D World. It will render coloured squares, circles, lines and points for...

Checking collision2D on children and parents

unity3d,game-physics,unityscript

Attach 2DColliders to both the parent and the child. Attach this same script to both parent and child. function OnCollisionEnter2D(coll: Collision2D) { if(transform.parent == null) Destroy(gameObject); else if(transform.parent != null) print("You win"); } ...

Ruby Gosu how to start new time on click

ruby,game-physics,libgosu

First you have the keyboard event handler in a wrong place. The update method serves only as a callback in update_interval period and you should definitely place it in button_down instance method of Gosu::Window. Second, if you call move method to update game objects positions it is meaningless to do...

How to make a timer for a game similar to 2048? [duplicate]

c++,timer,implementation,game-physics

One way you can implement a timer in c++ is to use the <ctime> library. A basic idea is to save the starting time and also save the ending time / current time. And then subtracting end - start to see if that has exceeded the max time (time moves...

Three.JS FPS Controls Strafing Left and Right

javascript,three.js,game-physics,physijs

A less computationally intensive way to calculate a vector in the left or right direction is by using the cross-product of of the cameraLookVector and a constant "up" direction. This assumes that the cameraLookVector is never parallel with this "up". In this image, we can choose the b vector as...

Make a sprite behave like a rigid body in Phaser.io

game-physics,phaser-framework

You need to use the P2 Physics system that comes with Phaser. Have a look at the Phaser Examples and scroll down to the P2 section specifically. There should be plenty of examples there to get you started, then you can use the API docs to fill in the blanks.

How to use AddForce and Velocity together?

c#,unity3d,game-physics,unityscript

It seems your move function is creating a new velocity vector and overwriting the existing one. Vector2 velocityVector = rigidbody.velocity; velocityVector.x += movement * force; rigidbody.velocity = velocityVector; This will retain the existing velocity, both X and Y, and modify it. You will of course need to add deceleration (usually...

How can I change velocity by a certain factor for a certain time, while remaining consistent at different framerates?

algorithm,game-physics,velocity,frame-rate

Imagining for a moment that your FPS will always be 30, can we express the velocity as a straightforward analytic function of the frame number, rather than as an incremental algorithm? Yes we can, v = 0.98 ^ frame_number. The ^ is exponentiation. Then we can reformulate that as a...

Move a Box with another on colission respecting the next neighboring mesh in Three.js

javascript,three.js,collision-detection,game-engine,game-physics

Pretty simple, it's more about geometry and logic than physics... if I understand your simplified world. In the case of boulderdash (or also sokoban), where the movement is tiled-based, when you are about to move the character you first check the adjacent tile, in the direction of the movement. It...

Missing Relative Transform in AddPhysicsHandleComponent

physics,game-physics,unreal-engine4

I think you can just call "Set Target Location and Rotation" on your physics handle.

andEngine: Why the touch event doesn't work?

java,android,touch,andengine,game-physics

Ok so the problem was that in onPopulateScene() i did not put pOnPopulateSceneCallback.onPopulateSceneFinished();. Turns out that even if you define your scene and sprites in onCreateScene() it is still needed t put that in onPopulateScene(). Still I will keep in mind that I should not put 'this' in constructor (even...

detect collision only on top of the object in box2d & cocos2dx

cocos2d-x,box2d,collision-detection,game-physics

I got the solution for my question from the below link. http://www.raywenderlich.com/28606/how-to-create-a-breakout-game-with-box2d-and-cocos2d-2-x-tutorial-part-2...

Physics with bouncing balls

java,swing,collision-detection,collision,game-physics

Real life physics is tricky (gravity, inertia, etc), but to start with, bouncing the balls off of each other: When the two balls hit, there's an angle of collision. Luckily, because they are circles (assuming) you can find the angle of incidence by finding the angle of the line going...

Making collisions work in Apple SpriteKit

ios,sprite-kit,collision-detection,game-physics

your nodes dont have a physicsbody assigned to them. you're assigning them physicsbody categories, but they have no physicsbody to begin with. It's nil! you need to do yournode.physicsBody = [SKPhysicsBody <some initializer>] ...

2D bouncing formula doesn't work properly

unity3d,game-physics,bounce,raycasting,unity3d-2dtools

Your raycast is likely hitting the wrong collider. You start it at transform.position. That is the center point of your ball object. Imagine a ray coming out of a circle's center. What's the first line it hits? It hits the circle itself first. So your Raycast reports the surface normal...

Jumping ball physics in java, gravity

java,game-physics,movement

On its iteration y gets lower than the X axis on the first run. Then being zeroed, So max height that you will get in that iteration is lower than original height. The same happens later, Until y will get to 0 without being set to it ( I think...

Rotate texture with Circlshape and Body

java,libgdx,textures,game-physics

you try Sprite.rotate(YourRotation); but keep in mind that body.getAngle() returns the rotation that has the body with respect to its initial position, I think you'll have to adjust for use with rotate. for example, take body.getAngle() between frame and frame and the difference the previous frame is that you apply...

Approach to sphere sphere collision

opengl,collision-detection,collision,game-physics

When writing collision detection algorithms, it is important to recognize objects are moving at discrete time steps, unlike the real world. In a typical modern game, objects will be moving with a time step of 0.016 seconds per frame (often with smaller fixed or variable time steps). It is possible...

Sprite kit physics in endless runner game?

cocoa-touch,sprite-kit,game-physics

The proper way is to center the scene on a node. The best way to learn how to do so is to go ahead and visit the docs here (go to section titled 'Centering Scene on a Node'), but if you encounter any problems with the implementation let us know!...

Can someone explain how to experiment with the value of gravity?

java,libgdx,physics,game-physics,orthographic

By "experimentally determined," the author just means trying various values until finding something that worked. There's no math or complex magic here. To experiment with it, just change it and run the program again. If you like what you see, use it. If not, adjust it accordingly. The number of...

accelerometer data not correct, delayed for few seconds

ios,swift,sprite-kit,game-physics

I have given priority to both functions and the issue seems fixed. let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT dispatch_async(dispatch_get_global_queue(priority, 0)) { // do some task dispatch_async(dispatch_get_main_queue()) { // code with priority } } ...

Friction in SpriteKit

swift,sprite-kit,game-physics,skphysicsbody

Here's an example of how to move a sprite based on touch. This approach uses the velocity property of the physics body to move the sprite, so it will interact appropriately with other physics bodies in the scene and be affected by damping, friction, etc. First, define the scale and...

How do i orient my bullets in the right direction?

matrix,rotation,processing,game-physics,angle

If you want to get an angle between 2 points you can use atan2 the following way: angle = atan2(playerY - bulletY, playerX - bulletX); //This angle is not returned in radians, to convert it simply use the function: angle = degrees(angle); Of course afterwards you have to draw the...

timing issues while creating replay of game (ghost for racing)

ios,objective-c,cocos2d-iphone,box2d,game-physics

One solution is to run the simulation at a fixed timestep. Let's say you choose 16ms per update. But you still want things to move scaled by actual time elapsed. Now suppose a frame took 20ms. That means you'll do one 16ms update and have 4ms left over for the...

How to make full body with PhysicsFactory.createTriangulatedBody() and EarClippingTriangulator in andEngine/Android

android,box2d,andengine,game-physics,sensor

SOLVED! Ok so the idea to check if our player body left the body of our path is to count borders playerbody passes. So in contactlistener we make beginContact to add one to some int variable (lets say bordersPassed) and endContact subtracts one from it. So when our player is...

Create Dynamic Body using cocos 2d js and Chipmunk

javascript,cocos2d-x,game-physics,chipmunk,cocos2d-js

Here you go: //Add the Chipmunk Physics space var space = new cp.Space(); space.gravity = cp.v(0, -10); //Optionally add the debug layer that shows the shapes in the space moving: /*var debugNode = new cc.PhysicsDebugNode(space); debugNode.visible = true; this.addChild(debugNode);*/ //add a floor: var floor = new cp.SegmentShape(this.space.staticBody, cp.v(-1000, 10), cp.v(1000,...

Swift SpriteKit Gravity Point

ios,swift,sprite-kit,game-physics

Sounds like a job for a radial gravity SKFieldNode. link

how to make a div stay in a div

html,css,css-position,game-physics

position:relative means relative to itself not parents/children etc. It seems likely that you want relative on the parent and possibly absolute on the children. Without code, it's hard to help much further Here's a quick demo for you. .container { width: 80%; height: 250px; margin: 0 auto; position: relative; border:...

Projectile Physics - Why do i get a different result when using Time.sinceLevelLoad over Time.delatime in Unity?

c#,vector,unity3d,game-physics

Time.deltaTime is the time interval being processed by this Update. At 30fps it is 1/30s assuming no variance in frame rate. For physics you should use FixedUpdate which is always a fixed interval. Time.timeSinceLevel load is at it says, the elapsed game time since loading the level. They are very...

Java Graphics Basics: Creating Collison Area From Image

java,android,image,game-physics

I suggest you to write an interface.Lets call it ImageInterface. Now in image interface you can have all basic image related stuff like getWitdh(), getHeight(), getPixelValue(x,y),draw() etc. Use that interface in all of your project. And implement it seperately for cros platforms. You can use BufferedImage for java and Bitmap...

is there a simple way to draw coordinates for SKnodes obstacles from images?

ios,swift,sprite-kit,game-physics,ios-universal-app

There is a SKPhysicsBody class method that could be of help: + bodyWithTexture:size: From the description: Use this method when your sprite has a shape that you want replicated in its physics body. The texture is scaled to the new size and then analyzed. A new physics body is created...

Acceleration goes to zero when opposite direction is quickly pressed in succession to last one.

python,pygame,game-physics

It may be that the opposite KEYDOWN event is being received before the KEYUP. I would guard the KEUP event handling to make sure the opposite KEYDOWN has not occurred. Something like: if event.key == K_RIGHT and active.dirx == 1: active.dirx=0 ... ...

Is this a physics bug with WheelCollider or am I doing something wrong?

unity3d,game-physics

Without really digging into it, my initial impression is that your WheelCollider friction values are probably too low. Increasing the forward friction will probably help with your inconsistent acceleration and the sideways friction will probably address your steering issue.

Keep node in view

ios,sprite-kit,physics,game-physics,skphysicsbody

A node does not remove itself from the view once it goes off screen. It's still there but no longer gets rendered. If it has a physics body, physics calculations are still ongoing despite being off screen. The only instance a node gets removed is if you remove it from...

How to reset its position back to the origin when it reach the end of frame? javascript

javascript,sprite,game-physics

I think that the create() method only gets called when you create it. This way the if statement only gets called once. You need to check it multiple times (eg each frame). it appears Phase has a class that checks if you're out of bounds. (onOutOfBounds) try: function create() {...

Everytime I draw list item in SFML it crashes?

c++,list,game-physics,sfml

Your for loop is a bit strange here: for(std::list<sf::Sprite>::iterator it = laserList.begin(); it != laserList.end(); laserList;) You'll find that this will form an infinite loop as the value of it never changes. This may be what leads to your crash. To fix it you want to increment the iterator after...

SpriteKit score is acting randomly

ios,objective-c,sprite-kit,game-physics

In Box2D (the physics engine that SpriteKit uses internally) a single contact can produce multiple invocations of the related callback function. So your score value is being incremented several times because your method didBeginContact is called multiple times for the same contact. You can prevent this behavior in several ways....

Need help creating rocks to spawn on random location

arrays,actionscript-3,loops,game-physics

You need something like this: var rocks = new Array(); // Create 10 rocks for ( var i = 0; i < 10; ++i ) { var rock = new Rock(); rock.x = Math.random() * stage.stageWidth; rock.y = 0; rocks.push( rock ); } stage.addEventListener(Event.ENTER_FRAME,stepDown); function stepDown(event:Event) { // step down...

Crossed Edge Collision in Cocos2d-x v3

cocos2d-x,collision-detection,game-physics,cocos2d-x-3.0

It seems you are using the cocos2d-x implementation for Physics. So, i have less idea about this. But Generally, this happens when update physics world update rate cycle is low, either by setting or low frame rate. check, UpdateRate of your world. From Doc: /** Set the speed of physics...

How to distribute a list of rectangles of varying width and height, maximizing distance between items, inside a rectangular container?

algorithm,game-physics,bin-packing

As you only need a heuristic, and not an optimal solution (which nobody can give you ATM, as "distances between items are maximized" is a vague term): Though bin-packing seems to be the "opposite", it can be used. Take a smaller (smallest) box that they fit into, and do the...

How can i make sprites spawn on random locations using pygame?

python,pygame,sprite,game-physics

To make them spawn in random locations use random.randint(a, b) to assign the start position.

Rotation of Sprite in touch event

ios,rotation,sprite-kit,game-physics

when you use rotateByAngle it's in radians. theres about ~6 radians in a circle. so you're rotating this sprite many times over. It isn't a 50 degree turn the way you'd expect. You need to be using variations of CGFloat(M_PI). If you want to convert between degrees and radians the...

How to not allow kinematic physics bodies to pass through static bodies?

android,box2d,andengine,game-physics

As @LearnCocos2D stated, I should reset platform body to a legal position while it tries to leave the screen. For this, I should use setTransform method of Body class (as @iforce2d said). For dealing with setTransform, there is two important points. AndEngine uses top-left as anchor of sprites, but Box2d...

How do I make the code Wait for a few milliseconds in C#?

c#,xna,collision,game-physics

If you look at your Update method definition (If you have a regular GameComponent or DrawableGameComponent) , you'll notice you have access to the GameTime: public override void Update(GameTime gameTime). You can use that variable to trigger the collision only after a set amount of time. To do that, surround...

Firing a shot from a character in the direction of mouse click

actionscript-3,math,game-physics

Math.atan2(y, x) will convert an x and y value into an angle: var mousePos:Point = localToGlobal(new Point(mouseX,mouseY)); var heroPos:Point = localToGlobal(new Point(Smallclock_hero.x, Smallclock_hero.y)); var dx:Number = mousePos.x - heroPos.x; var dy:Number = mousePos.y - heroPos.y; var radians:Number = Math.atan2(dy, dx); // Convert the radians value to degrees var angleInDegrees:Number =...

top down car when making a turn the sprite separates to the body [closed]

java,android,libgdx,game-physics

Try setting the origin of the sprite to center with: setOrigin(sprite.getWidth() /2f, sprite.getHeight() /2f); This will make rotations and scalings use that point instead of default (0, 0)...

Bullet Physics - Creating ShapeHull from Mesh

c++,opengl,game-physics,physics-engine,bulletphysics

Maybe, not the answer you're looking for, but probably you could use btConvexHullShape, as advised in Bullet documentation? http://bulletphysics.org/Bullet/BulletFull/classbtConvexTriangleMeshShape.html Nevertheless, most users should use the much better performing btConvexHullShape instead. And add vertices one by one using addPoint, which is also mentioned in documentation: http://bulletphysics.org/Bullet/BulletFull/classbtConvexHullShape.html It is easier to not...

SpriteKit Collision without Tilting

objective-c,sprite-kit,game-physics

The answer is simple. Set the SKPhysicsBody's allowsRotation to false. A Boolean value that indicates whether the physics body is affected by angular forces and impulses applied to it. ...

Find whether a triangle and polyhedron (represented by planes) intersect

math,graphics,geometry,game-physics,intersection

As @NicoSchertler suggested in a comment, a solution is to take each triangle and clip it on all the planes. If there are no points left (or under 3 points, so it is not a triangle), the triangle intersects the polyhedron. This seems to work well.

XNA Diagonal Movement Key Release

c#,xna,game-physics,movement

So I figured out the answer myself after a few hours of struggle. Simply setting the velocity to zero before the checks worked: EDIT: multiplying it by .89 actually made for much smoother movement. if (kb.IsKeyDown(Keys.W) || kb.IsKeyDown(Keys.A) || kb.IsKeyDown(Keys.S) || kb.IsKeyDown(Keys.D)) { velocity *= .89f if (kb.IsKeyDown(Keys.W)) velocity.Y =...

Unity2D collisions and some physics

c#,unity3d,2d,game-physics,collisions

I managed to fix my both problems. To fix problem number 1. I used add force. My new moving forwand and backward looks like this: if (Input.GetKey (MoveForward)) { //transform.Translate (Vector2.right * thrust); OLD !! rb2D.AddForce(transform.right * thrust * Time.deltaTime); } if (Input.GetKey (MoveBackward)) { //transform.Translate (Vector2.right * -thrust); OLD...

Slick2 / dyn4j render loop performance when iterating number of bodies

java,performance,game-physics,slick2d

Turns out it isn't the graphics drawing routine... it is the dyn4j iteration of the fragments during the World.update() method. Changing the fragment Fixtures to sensors (Fixture.setSensor(true)) so they detect collisions, but don't respond to them, resolves the performance issues and I get about 130FPS if I run the game...

How do I give the basket its exact shape, for a physics body, it is an image?

swift,sprite-kit,game-physics,skphysicsbody

You could use init(texture:size:) to create an SKPhysicsBody that matches the texture used by the basket. Here's an example: let basket = SKSpriteNode(imageNamed: "basket") basket.physicsBody = SKPhysicsBody(texture: basket.texture!, size: basket.size) // Do the rest of the setup. In the example above I'm force unwrapping the basket's texture property because I...