physics

SpriteKit drag and drop through wall

徘徊边缘 提交于 2019-12-24 00:46:53
问题 I did simple drag and drop in SpriteKit with physics. It works as expected, but when I use fast drag, element goes through wall. self.runner is wall self.runner2 is square Wall have dynamic set to NO. Movie shows everything: https://www.dropbox.com/s/ozncf9i16o1z80o/spritekit_sample.mov?dl=0 Tested on simulator and real device, both iOS 7. I want to prevent square from going through wall. Any ideas? #import "MMMyScene.h" static NSString * const kRunnerImg = @"wall.png"; static NSString *

Whats the best way to do character animations with Box2D?

北战南征 提交于 2019-12-23 17:41:57
问题 I am developing a 2D, underwater, action-RPG for Android, using Box2D as the physics engine, mainly for collision detection, collision response and movement of in-game characters within an environment comprised of walls, rocks, and other creatures. I have tried two different approaches for implementing character animations using Box2D, and have found issues with both. As I'm new to Box2D and physics engines, I would appreciate a recommendation on how these things should best be done. An

angle for particular co-ordinate in projectile path?

前提是你 提交于 2019-12-23 05:18:20
问题 I have xy co-ordinate like (200,200). I know the angle calculation from the origin the ball throws. How can I find the initial velocity to reach that particular xy co-ordinate when ball is thrown in 2d Environment? Iam using x = v0cosq0t; y = v0sinq0t - (1/2)gt2. but time is needed. Without time can I do it? any help please? 回答1: I'm assuming that you want the ball to hit that specific point (200,200) at the apex of its path. Well, my physics is a bit rusty, but this is what I've thrown

Rigid body (shape) in bullet/ammo.js from a mesh in three.js

自作多情 提交于 2019-12-23 01:38:11
问题 I am using bullet/ammo.js with three.js. I have a 3d mesh and I want to use the exact shape for collision detection with a soft body. Is there a way I can create a 3d rigid body (in bullet) from a mesh (in three.js)? Here is an example: http://kidzinski.com/miamisura/lazy3d/ (please wait a second for the 3d model to download). I have a cloth falling on a 3d body and I need to simulate collision of this cloth with the body. I am new to these frameworks sorry if I fundamentally misunderstood

SpriteKit joint: follow the body

有些话、适合烂在心里 提交于 2019-12-23 01:06:14
问题 I've been asked to simplify this question, so that's what I'm doing. I'm struggling in SpriteKit's physic joints (and possibly physic body properties). I tried every single subclass and many configurations but seams like nothing works or I'm doing something wrong. I'm developing Snake game. User controls head of snake which should move at constant speed ahead and user can turn it clockwise or anticlockwise. All the remaining snake's pieces should follow the head - they should travel exactly

Simulating movement similar to dust particles

回眸只為那壹抹淺笑 提交于 2019-12-22 18:43:00
问题 I've tried a setInterval loop with css and animate. Both ways of movement consists of tiny movement from oldpos1 -> newpos1 with no random curve movement, easing however occured with jQuery animate but only between randomly generated 1-3 pixels, which is not what I want . Does the problem lies in setInterval 's clock, where only linear time units flow? Where should I start, to make below images exist in jQuery? What I would like to do: Dodge behaviour: A, B - particle AB1 - common dodge area,

Box2D: How to manually render a body

邮差的信 提交于 2019-12-22 18:32:38
问题 I succeed installing Box2D into my project. But how can I render a body? Assume I'm using something that supports drawing polygons. I just want to find out the current positions of the vertices of the body-polygon, to draw it with the engine. If you can help me, I will be very thankful. 回答1: I found it!!! void Box2DUtils::DrawBody(SDL_Surface *buffer, b2Body *body, int fr, int fg, int fb, int falpha, int lr, int lg, int lb, int lalpha, bool aa) { const b2Transform& xf = body->GetTransform();

Centroid of convex polyhedron

北城余情 提交于 2019-12-22 04:50:12
问题 I have a closed convex polyhedron which is defined by an array of convex polygons (faces) which are defined by arrays of vertices in 3D space. I'm trying to find the centroid of the polyhedron, assuming uniform density. At the moment I calculate it with the algorithm in this pseudo-code. public Vector3 getCentroid() { Vector3 centroid = (0, 0, 0); for (face in faces) { Vector3 point = face.centroid; point.multiply(face.area()); centroid.add(point); } centroid.divide(faces.size()); return

Position resizable circles near each other

时间秒杀一切 提交于 2019-12-22 03:54:06
问题 I am working on this browser-based experiment where i am given N specific circles (let's say they have a unique picture in them) and need to position them together, leaving as little space between them as possible. It doesn't have to be arranged in a circle, but they should be "clustered" together. The circle sizes are customizable and a user will be able to change the sizes by dragging a javascript slider, changing some circles' sizes (for example, in 10% of the slider the circle 4 will have

Computing mean square displacement using python and FFT

∥☆過路亽.° 提交于 2019-12-21 20:24:00
问题 Given a 2 dimensional array, where each row represents the position vector of a particle, how do I compute the mean square displacement efficiently (using FFT)? The mean square displacement is defined as where r(m) is the position vector of row m, and N is the number of rows. 回答1: The following straight forward method for the msd works, but it is O(N**2) (I adapted the code from this stackoverflow answer by user morningsun) def msd_straight_forward(r): shifts = np.arange(len(r)) msds = np