game-physics

(Physics engine for games like Sugar, Sugar) SpriteKit performance optimization for many physics sprites

懵懂的女人 提交于 2019-12-13 03:36:17
问题 I'm a iOS game developer and I saw an interesting physics & draw game "Sugar, Sugar" recently. In the game, there are lots of pixel particles (thousands of them) generated from the screen and free falling to the ground. Player can draw any shape of lines, which can guide those particles to certain cups. A image from google: I'm trying to achieve similar effect using SpriteKit with Swift. Here's what I got: Then I encounter a performance problem. Once the number of particles > 100. The CPU and

Box2D and wrapping worlds

对着背影说爱祢 提交于 2019-12-13 03:17:22
问题 I really stuck at implementing wrapping world with Box2D. I want to create game object appearing from left when it hides to the right and vice versa and the same for top-down. My idea is to use object wich contains NSArray with 9 elements for superposition matrix (it's a quantum state when object exists at different locations at the same time, isn't it?). Every element must contain the body. It covers all situations and has a more clear logic for me. For example, if my object doesn't touch

Using Generic Functions for collision detection in C# / XNA

别等时光非礼了梦想. 提交于 2019-12-13 02:29:16
问题 I am making a physics engine in c# / XNA, I have three basic objects... Sphere Cube Plane that are all derived from GameObject I store all my objects in a list of GameObjects and I would like to loop through this list and be able to call a CheckCollision function that will go to the correct function for each pair of objects eg go is a Sphere, go2 is a Sphere if(CheckCollision(go, go2)) { //do stuff } bool CheckCollision(Sphere one, Sphere two) { //Check Sphere to Sphere } bool CheckCollision

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

有些话、适合烂在心里 提交于 2019-12-13 02:02:52
问题 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 are moveable. Push or Pull box 4 to west: Should move box 3 to west on collision. Should make box 3 and 4 not able to move west when box 3 hits box 2. Push 2, 3 or 4 to north: Should stop when it hits box 2, because box 1

Why does the height of the rectangles jump vary?

随声附和 提交于 2019-12-13 01:34:45
问题 Why does the height of the rectangle's jump vary? It seems to go in a cycle. First it jumps low then it doesn't jump at all then it jumps high then it doesn't jump at all. i can't figure out why as the same code is used and it is triggered by the same event. import java.awt.Color; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.event.KeyEvent; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.event.KeyEvent; import

How to access Physics World in Layer

拟墨画扇 提交于 2019-12-13 01:29:27
问题 I need to create joint between two bodies in layer. Joints are to be added in physics world. How can i access physics world in layer? 回答1: My JavaScript implementation. Hope it will help. var space; function initPhysics() { space = new cp.Space(); space.gravity = cp.v(0, -800); space.iterations = 30; space.sleepTimeThreshold = Infinity; space.collisionSlop = Infinity; } function addJoints() { chainTableJoint1 = new cp.PivotJoint(chainEnd1, tableBackBody, cp.v.add(cp.v(chainEnd1.getPos().x,

Three.js How to make a camera follow a terrain heightmap?

走远了吗. 提交于 2019-12-12 18:25:54
问题 I have a terrain mountain range with a camera fly view positioned close to the heightmap. The camera is controlled using standard keyboard controls that doesn't allow movement in y axis; it stays on it's set y-axis. Since the terrain is not an even level and randomly renders. How can I get the camera to follow the terrain heightmap? Here is an example. Below is an attempt to add raycaster to scale over the terrain. All code is in the animate function in project. I noticed that when the camera

Projecting Objects Out Of Collision

自闭症网瘾萝莉.ら 提交于 2019-12-12 18:09:12
问题 As a hobby, I'm developing a 2D game. I've got some basic collision detection implemented using a separating axis method. When two objects collide, I project one of them out of collision along the axis that has the least amount of overlap. The problem I'm encountering is that when an object is moving fairly quickly the axis that has the least amount of overlap isn't always the correct direction. The best example I have is when an object is moving down (along the + y axis) due to a simulated

Entity Component System and multiple components sharing common base type

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 15:34:50
问题 I'm trying to implement a simple ECS for my game engine. I know that my implementation is not strictly ECS, but I'm refactoring my code to be more component-based. So far I have the following classes: Entity : it is a container of components, and since I want my entity to have multiple components of the same type, it stores them in a std::map<ComponentID,std::vector<std::unique_ptr<Component>>> . Each component has a unique ID (an unsigned int), that I get from a simple template trick I

Quaternion from Orthogonal Basis

可紊 提交于 2019-12-12 10:53:55
问题 I have a projectile object that is moving along a velocity vector. I need to ensure that the object is always facing in the direction of the velocity vector. Furthermore, I am representing object rotation using quaternions, not matrices. I know that the first step is to find an orthogonal basis: forward = direction of velocity vector up = vector.new(0, 1, 0) right = cross(up, forward) up = cross(forward, right) How might I convert the basis into a rotation quaternion? Solution Note, I'd like