FAQ Database Discussion Community


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

javascript,three.js,collision-detection,game-engine,game-physics
Found a lot of physic engines out there but nothing that fit my needs directly. I try to to find a simple way to push and pull boxes including collision detection which respects the next neighboring mesh hit while moving. Some use cases to understand: All boxes except box 1...

Sprite kit physics in endless runner game?

cocoa-touch,sprite-kit,game-physics
How would I use sprite kit physics in my endless runner game? An endless runner fakes motion by keeping the player stationary but moving the background and all the other objects by a set speed. BUT, I want to simulate physics. What if I let my player move with the...

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

ios,objective-c,sprite-kit,game-physics,skspritenode
In my game, I need to do some setting changes after my SKSpriteNode stops moving. First, I apply force on my SKSpriteNode, so it starts moving due to the force acting on it. Now, i need to know when it stops moving. I know that SKSpriteNode has a speed property,...

How to use AddForce and Velocity together?

c#,unity3d,game-physics,unityscript
I have the jump component who use the AddForce for jumping and the movement component who move left and right using the Velocity. If you don't move the character when your are jumping the jumping will be fine but when you move the character and jump at the same time...

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
This is for a game, and I want the velocity of a certain object to decrease at a rate of 98% per frame, when the framerate is 30 frames per second. But, the framerate can be anything between 30 and 60 frames per second. The best solution I came up...

how to make a div stay in a div

html,css,css-position,game-physics
I'm making a pong clone using HTML/CSS/Js. I've set a div element to act as a border for the game, just to keep things in a confined space. How do I get elements (for example, a scoreboard) to act relative to their parent element? For example, if I tell the...

accelerometer data not correct, delayed for few seconds

ios,swift,sprite-kit,game-physics
I am creating a very simple game using Swift and SpriteKit and I am moving a ball on the screen using the accelerometer data (acceleration x,y). I would say the code works fine but I have noticed that sometimes (often right when I open the app) the accelerometer data is...

Box2d Body to follow mouse movement

libgdx,box2d,game-physics
I am trying a box2d body to rotate following the mouse. Here's an image to clarify what I mean. The red and blue circles are current point of the mouse and the body (of corresponding color) moving/rotating to follow it. Basically the rectangle should rotate with its one end pointed...

XNA Diagonal Movement Key Release

c#,xna,game-physics,movement
Ok, so say you're playing a top down game. You press W and D to go in the up-right direction. Now you just want to go right, so you release the W key. One would expect you to then change directions and head right, but instead, you continue up-right. What...

Acess normal force/impulse between rigid bodies

unity3d,game-physics
I'm making a catapult game in Unity 3d. When the stones from my catapult hit the walls of enemy castles, or when a tower of an enemy castle crumbles together, I will need the force between rigid bodies, to calculate damage. Relative velocity is not enough, as it does not...

Accurate Circular Orbit Equation in java

java,2d,game-physics,gravity,orbital-mechanics
public void move(){ double angle; for(int i = 0; i < planets.size(); i++){ if(Math.abs(Math.sqrt(Math.pow(ship.locX - (planets.get(i).locX + planets.get(i).radi), 2) + Math.pow(ship.locY - (planets.get(i).locY + planets.get(i).radi), 2))) < planets.get(i).gravrange){ //Distance formula between spaceship and planets to determine whether the ship is within the influence of the planet. angle = ((Math.atan2((planets.get(i).locX +...

Set the maximum and current speed of a car in Phaser

javascript,game-physics,phaser-framework,racing
I am making a top-down racing game using the Phaser framework which uses JS. I am having some trouble getting the car to slow down, at the moment it just stops when no button is pressed. I want it to slow down to stopped. Here is my code so far:...

Point adding mechanism troubles?

java,android,game-physics
I have this game where the goal is to pass a ball through oncoming rectangles with gaps in them. Point gains are registered when the ball's x position falls within a certain margin (plus or minus) from the right of the rectangle being passed by the ball. Since the timer...

Ruby Gosu how to start new time on click

ruby,game-physics,libgosu
Im trying to simply move an image on click from the one side of the screen to another. But I can't quite figure out how to work with time. Basically I need to start moving a ball after a Gosu::KbReturn. Any help would be much appreaciated require 'gosu' def media_path(file)...

Missing Relative Transform in AddPhysicsHandleComponent

physics,game-physics,unreal-engine4
I'm trying to rebuild the tutorial "Pick Up Physics Object Tutorial" and I need to use "Relative Transform" in "AddPhysicsHandleComponent" but it is not there. On this site https://docs.unrealengine.com/latest/INT/BlueprintAPI/AddComponent/Physics/AddPhysicsHandleComponent/index.html the AddPhysicsHandleComponent is shown exactly the way I need it but in Unreal Engine itself it appears without the "Relative Transform"....

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
I need a function that takes in two inputs: a bounding box with a width and height an array of rectangular items with varying width and height (all smaller than the bounding box) It would output an array of the same items with an additional position property (can mutate the...

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

libgdx,game-physics
I have an array of blasts, and an array of zombies, but I'm struggling to find a way to efficiently detect collisions and remove both the blasts and zombies that have collided. Any suggestions? Iterator<Rectangle> blastIter = blasts.iterator(); while(blastIter.hasNext()) { Rectangle blast = blastIter.next(); blast.x += 200 * Gdx.graphics.getDeltaTime(); if(blast.x...

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

ios,swift,sprite-kit,game-physics,ios-universal-app
I am creating a game and I need to draw some obstacles on in (SKNodes), depending on the level (background image). Let's say I have a tree, i would like to draw borders around it as in the picture below: I will need the coordinates to create a physicsBody. Is...

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

swift,sprite-kit,game-physics,skphysicsbody
basket.position = CGPointMake(self.size.width/2, self.size.height/8) basket.size.height = 50 basket.size.width = 75 basket.name = "basketNode" basket.physicsBody = SKPhysicsBody(rectangleOfSize: basket.size) basket.physicsBody?.usesPreciseCollisionDetection = true basket.physicsBody?.categoryBitMask = basketCategory basket.physicsBody?.dynamic = false self.addChild(basket) So currently, balls are falling from top of the screen, the players job is to catch them in the basket, for it to...

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

c#,xna,collision,game-physics
I have made some collision if statements, but they didn't work. birdbox3.X += 5; birdbox3.Y -= 5; if (birdbox3.Intersects(Banner1)) { birdbox3.Y += 10; } else if (birdbox3.Intersects(Banner2)) { birdbox3.Y = -birdbox3.Y; } So if we take the first statement, the box is initially on the left down corner. According to...

Movement of sprite using fixed time step

c++,game-engine,game-physics,sfml,movement
I have this loop: sf::Clock clock; sf::Time timeSinceLastUpdate = sf::Time::Zero; while (mWindow.isOpen()) { processEvents(); timeSinceLastUpdate += clock.restart(); while (timeSinceLastUpdate > TimePerFrame) { timeSinceLastUpdate -= TimePerFrame; processEvents(); update(TimePerFrame); } render(); } and in update function I do this: object.speed = object.speed * TimePerFrame.asSeconds(); and then I run a method in which...

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

python,pygame,sprite,game-physics
Ive been trying to make a twist on a dodger-like game, where some blocks make you grow and others make you shrink. I'm also planning to add a red one of which is supposed to make you lose a life(you will have 3 lives starting out), and various others with...

Keep node in view

ios,sprite-kit,physics,game-physics,skphysicsbody
I have a question: Typically, a node will be removed from the view of its position if it exceeds the device's height. I'm using gravity so it falls back down into the view. How would I make it so the node doesn't remove itself from the view?...

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

ios,swift,sprite-kit,game-physics
I am creating a game where a ball is moving on the screen and I would like to create a hole where the ball can go inside (as it happens in billiard) Can that be a simple circle SKNode with a black background? In this case I should hide the...

moving physics body at a constant speed

game-physics,rigid-bodies
I am working with a 2D physics engine that has the typical physics properties on a rigidbody get/set mass, friction, bounce, gravity, linear damping, linear velocity, impulses. I would like to move this rigidbody at a constant speed, is there some formula that I can use to uses those forces...

Andengine - RevoluteJointDef torque

andengine,game-physics,revolute-joints
I am following this amazing tutorial (http://www.matim-dev.com/revolute-joint.html) to create a RevoluteJointDef, just like the blog describes. Everything worked as it is explained, BUT I am getting an undesirable behavior. Problem: When my body(1x1 meter) ball fall over(colide) the rotating body, it slow down for a while, even if I set...

Physics with bouncing balls

java,swing,collision-detection,collision,game-physics
Is this the right site to ask this question, since I've been referred to another site two times by now. I'm trying to create bouncing balls with realistic physics. At the moment, when the balls hit each other, they bounce back in the same direction they were coming from, now,...

Large-scale spherical world in a physics engine

game-physics,physics-engine,cannon.js
(This question is targeted at Cannon.js (by @schteppe), but hopefully answer(s) will be applicable to other engines for the benefit of others not using Cannon.) It seems like one strategy for building a huge spherical world in a physics engine is to start with 6 heightmaps forming a cube, and...

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

c#,vector,unity3d,game-physics
I'm playing around with projectile physics on objects in Unity. In this case I'm just using a sphere object and calculating it's vector and the path it should take based on gravity (leaving other forces like friction out for the moment). The formula I'm using is the following: s =...

Create Dynamic Body using cocos 2d js and Chipmunk

javascript,cocos2d-x,game-physics,chipmunk,cocos2d-js
I am fairly new to cocos 2d and chipmunk. So far i have managed to create a static object and add collision handler to it. But i want to create a dynamic.``this.space = space; this.sprite = new cc.PhysicsSprite("#rock.png"); var body = new cp.StaticBody(); body.setPos(pos); this.sprite.setBody(body); this.shape = new cp.BoxShape(body, this.sprite.getContentSize().width,...

Java 2D Platformer Gravity

java,game-physics
I am currently making a 2D Platformer in Java. I am a beginner so take it easy. I have a problem with the gravity in the game. I am using different variables for falling and jumping. I am using a tiled map. So lets get to the point. My fall...

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

ios,objective-c,cocos2d-iphone,box2d,game-physics
I have created an iOS game in cocos2d that uses box2d for physics. I would like to have a replay function for this game (where you can race a ghost of your previous attempts) I know box2d is deterministic (well it is for the same hardware... so running this on...

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

java,android,box2d,andengine,game-physics
I am working on AndEngine, and stuck to know the exact height and width of the PhysicsWorld which I used in meters. 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); ...

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

unity3d,game-physics
I'm trying to figure out how to stop the rotation of a rigidbody using inertia in Unity 3D. This is how I assumed it should be done, but when I ran it, it crashed Unity and I had to kill the process. while(rigidBody.angularVelocity.magnitude != 0) { rigidBody.AddTorque(-transform.up * REACTION_WHEEL, ForceMode.Impulse);...

Getting distance between point of an object and another object

c#,unity3d,game-physics
First, I'd like to apologize because this is a very basic and repetitive question, but I am completely new to game development. I understand that I can find a distance between two objects using: float dist = Vector3.Distance(other.position, transform.position); However, how can I find the distance between a point of...

Android libgdx bouncy screen bounds

android,libgdx,game-physics,bounce
I need to set phone's bounds as a wall where elements inside can bounce. The physic should be correct. Here an example : I know that Interpolation allow bounce but I don't know how to create the physics...

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

c#,unity3d,game-physics
I have a ball that has an initial burst of force, launching it into the air. This ball would ideally then be able to veer towards its target while continuously losing that starting momentum. It shouldn't gain any velocity when heading towards its target. Importantly! It can also bounce against...

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

java,libgdx,physics,game-physics,orthographic
I am following a guide on how to play a flappy bird clone in the LibGdx framework. -http://www.kilobolt.com/day-5-the-flight-of-the-dead---adding-the-bird.html I am currently on the part where the author discusses adding the actual bird and the physics behind the bird. He encapsulates the state of the bird with these instance variables private...

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

android,box2d,andengine,game-physics
My game scene consist of four walls, which are static bodies, and one platform plate, which is of type kinematic and slides only horizontally, something like the picture below. The platform body moves based on acceleration sensor, see this codes @Override public void onAccelerationChanged(AccelerationData pAccelerationData) { mPlatformBody.setLinearVelocity(pAccelerationData.getX() * 10, 0);...

Three.JS FPS Controls Strafing Left and Right

javascript,three.js,game-physics,physijs
I am setting up a simple demo to test player controls for a FPS. I have the mouse rotating the camera and the player can move with Q-A-S-D. My question is what is the algorithm I need for the player to be able to move left and right relative to...

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

math,graphics,geometry,game-physics,intersection
I am given a polyhedron which is represented by a list of planes. The volume delimited by these planes is the actual polyhedron. I have a list of triangles, and I need to remove all the triangles that intersect or is contained in this polyhedron. My idea is to check...

Swift Spritekit Contact Bitmask and Score Label

ios,swift,sprite-kit,game-physics,bitmask
I am a fairly new programmer, attempting to make it so that during a bricked breaker like game, when the ball hits the paddle, I would like to add one point to the score. I think I am partway there, but cannot figure it out. let BallCategory : UInt32 =...

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

unity3d,game-physics
I am trying to create a drivable car model using Unity's WheelColliders and I have set up my CarControl.cs script like this: https://gist.github.com/victorbstan/e5903829576eaf6ce5e3 I am encountering two problems: The car slightly turns without any steering being applied on a completely flat surface. The vehicle accelerates and decelerates inconsistently given the...

Date getTime gives low values for longer durations

javascript,game-physics,craftyjs
I am using Date().getTime to measure the duration of a keypress by subtracting the keydown event from the keyup event. However, for keypresses longer than ~500ms, the recorded time appears to return to a lower value. Here is the JSFiddle http://jsfiddle.net/bdzaorw2/ $(document).ready(function(){ Crafty.init(window.innerWidth,window.innerHeight); var player = Crafty.e(); //... function horizontal(){...

Arduino Esplora Pong Game

c,arduino,game-physics,pong
Over the last couple of days I've been working on a Pong game for Arduino Esplora with Arduino's TFT display. Everything in the game works except that, when the player scores the ball gets deleted from it's last location and reappears in the center (as it should), while when the...

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

javascript,sprite,game-physics
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create}); function preload() { // You can fill the preloader with as many assets as your game requires // Here we are loading an image. The first parameter is the unique // string by which we'll identify the...

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

unity3d,game-physics,physx
I've read in a lot of places that having two objects colliding with each other where the mass of one is over 100 times greater than that of the other will cause issues with the physics of the collision. However when I tested it myself I found no real issue...

how to Detect Collision and Remove body and image after Collision

java,android,collision-detection,andengine,game-physics
I am new on AndEngine and trying to detect collisions and destroy the body on collision. So far I have tried this. if (testingsprite.collidesWith(testingSprite1)) { Log.d("TAG", "Collisoion"); mphysicworld.destroyBody(myBody); scene.detachChild(testingSprite1); myBody = PhysicsFactory.createCircleBody(this.mphysicworld, testingSprite1, BodyType.DynamicBody, FIXTURE_DEF); }else{ Log.d("TAG", "else Collisoion"); } ` But it does not work, and always goes into...