game-physics

Continuous movement with a single key press?

房东的猫 提交于 2019-12-01 11:43:18
I'm trying to make a program in java that involves making an object move constantly from a single key press. Think Pacman, where you press up once and Pacman continues to go up until you press another key. I want to keep the code simple if possible. My original movement (one keypress = one movement) is like this: public class AL extends KeyAdapter { public void keyPressed(KeyEvent e){ int keyCode = e.getKeyCode(); if(keyCode == e.VK_A){ x -= 5; } if(keyCode == e.VK_D){ x += 5; } if(keyCode == e.VK_W){ y -= 5; } if(keyCode == e.VK_S){ y += 5; } } The x and y in values are the position of an

Calculating angular velocity after a collision

最后都变了- 提交于 2019-12-01 09:04:19
I've got the linear component of collision resolution down relatively well, but I can't quite figure out how to do the same for the angular one. From what I've read, it's something like... torque = point of collision x linear velocity . (cross product) I tried to incorporate an example I found into my code but I actually don't see any rotation at all when objects collide. The other fiddle works perfectly with a rudimentary implementation of the seperating axis theorem and the angular velocity calculations. Here's what I've come up with... Property definitions (orientation, angular velocity,

linearGravityField() is not affecting physics bodies in the scene SceneKit

我们两清 提交于 2019-12-01 08:39:09
问题 I'm trying to use a SCNPhysicsField.linearGravityField object to affect only specific objects in my scene. The problem is, that I can't seem to get it to affect anything. Here's a sample of my code in Swift: let downGravityCatagory = 1 << 0 let fieldDown = SCNPhysicsField.linearGravityField() let fieldUp = SCNPhysicsField.linearGravityField() let fieldNode = SCNNode() let sceneView = view as! SCNView sceneView.scene = scene sceneView.scene!.physicsWorld.gravity = SCNVector3(x: 0, y: 0, z: 0)

Shake a UIView … BUT using UIKit Dynamics

那年仲夏 提交于 2019-12-01 06:15:01
There are many situations where you need to "shake" a UIView. (For example, "draw child user's attention to a control", "connection is slow", "user enters bad input," and so on.) Would it be possible to do this using UIKit Dynamics? So you'd have to .. take the view, say at 0,0 add a spring concept give it a nudge, say to the "left" it should swing back and fore on the spring, ultimately settling again to 0,0 Is this possible? I couldn't find an example in the Apple demos. Cheers Please note that as Niels astutely explains below, a spring is not necessarily the "physics feel" you want for some

Simulating orbits using laws of physics

若如初见. 提交于 2019-11-30 20:08:33
Over the past couple of weeks I've been trying to simulate orbits in a solar system simulation I am making as part of a University module. To cut things short, my simulation is written in C++ using the Ogre3D rendering engine. I have attempted to implement orbits using Newton's law of universal gravitation which made my planet head towards the sun in a straight line, pass through the sun and then come back to its starting position. I also tried the steps from 'Position as a function of time' section of this wikipedia article , but that did not work for me either. I am driving the simulation

Reflection? How do I do it?

老子叫甜甜 提交于 2019-11-30 15:51:37
问题 This is over my head, can someone explain it to me better? http://mathworld.wolfram.com/Reflection.html I'm making a 2d breakout fighting game, so I need the ball to be able to reflect when it hits a wall, paddle, or enemy (or a enemy hits it). all their formula's are like: x_1^'-x_0=v-2(v·n^^)n^^. And I can't fallow that. (What does ' mean or x_0? or ^^?) 回答1: The formula for reflection is easier to understand if you think to the geometric meaning of the operation of "dot product". The dot

Reflection? How do I do it?

女生的网名这么多〃 提交于 2019-11-30 15:41:20
This is over my head, can someone explain it to me better? http://mathworld.wolfram.com/Reflection.html I'm making a 2d breakout fighting game, so I need the ball to be able to reflect when it hits a wall, paddle, or enemy (or a enemy hits it). all their formula's are like: x_1^'-x_0=v-2(v·n^^)n^^. And I can't fallow that. (What does ' mean or x_0? or ^^?) The formula for reflection is easier to understand if you think to the geometric meaning of the operation of "dot product". The dot product between two 3d vectors is mathematically defined as <a, b> = ax*bx + ay*by + az*bz but it has a nice

How to implement a physical effect in SimCity 5, that a building swings when it is being moved?

会有一股神秘感。 提交于 2019-11-30 14:06:22
问题 It is hard to describe in plain text, so I recorded a GIF to demonstrate. https://public.lightpic.info/image/2B1F_582465841.gif I am currently working on a project that requires such effect. Up to now I have finished a similar effect on iOS with SpriteKit, however unfortunately it turns out the result is not pretty satisfying. This is my work: in my project there is an object with an irregular shape, a constant force is applied at somewhere below the gravity center of the object and its

Movement Without Framerate Limit C++ SFML

拟墨画扇 提交于 2019-11-30 10:04:02
I'm working an making a game in SFML right now, but I am getting stuck on movement without a framerate limit. Right now the only way I have figured out how to get consistent framerate on all computers is by using window.setFramerateLimit(30); I want to find a way to not have a framerate cap so it does look better on better computers and so that if anybody has a really slow computer, they can still play the game. What would be the best way to do this. You should pass the time that has elapsed since the last frame to the object that needs to be drawn, and then calculate the space the object has

How to implement a physical effect in SimCity 5, that a building swings when it is being moved?

淺唱寂寞╮ 提交于 2019-11-30 09:34:08
It is hard to describe in plain text, so I recorded a GIF to demonstrate. https://public.lightpic.info/image/2B1F_582465841.gif I am currently working on a project that requires such effect. Up to now I have finished a similar effect on iOS with SpriteKit, however unfortunately it turns out the result is not pretty satisfying. This is my work: in my project there is an object with an irregular shape, a constant force is applied at somewhere below the gravity center of the object and its direction is downward. I have made it a rule that the object's coordinate cannot be changed by the force, so