game-physics

Is this plane-ray intersection code correct?

て烟熏妆下的殇ゞ 提交于 2019-12-07 18:18:40
问题 My Plane class has two fields: public Vector3 Norm; //normal vector public double Offset; //signed distance to origin This is the code I use for intersection, and I don't know if it is correct. I double checked my equations and everything, but I would like to get feedback from people more experienced with this. public override Intersection Intersect(Ray ray) { // Create Intersection. Intersection result = new Intersection(); // Find t. double t = - (Vector3.Dot(Norm,ray.Start) + Offset) /

How to make a projectile turn with a arc

孤街浪徒 提交于 2019-12-07 17:55:18
问题 I have a cannon that fires a bullet in a parabolic arc. Right now when I fire the bullet stays in the same rotation as it was when it fired out of the cannon. How do I make it so the bullet's rotation follows the arc as it travels through the air? I tried the following as a script running on the bullet Exhibit 1 public class PointingBehaviour:MonoBehaviour { private Rigidbody rb; private void Awake() { rb = GetComponent<Rigidbody>(); } public void Update() { transform.up = rb.velocity; } }

Calculate a trajectory for an object, when given an angle and a velocity in flash

孤人 提交于 2019-12-07 17:40:38
问题 I am trying to launch a cannonball from a cannon and have it follow a realistic path. The angle of fire changes depending on the orientation of the cannon (automatically orientates to mouse pointer). So what I'm trying to figure out, is how to move a cannonball along a parabolic path, when given an angle, and a set velocity. I've read that this can be done without complicated trigonometry (never listened to it in highschool), and can be calculated simply by adding gravity to the yVelocity

magnetism simulation

喜你入骨 提交于 2019-12-07 12:21:31
问题 Say I have p nodes on a n by m pixel 2D surface, I want the nodes to be attracted to each other such that the further they are apart the strong the attraction. But if the distance between two nodes, say d(A,B) is less than some threshold say k then they start to repel. Could anyone get me started on some code on how to update the co-ordinates of the nodes over time. I have something a little like the code below which is start to do the attraction, but looking for some advice. (P.S. I can not

2d Ball Collision Problem: no conservation of energy

烂漫一生 提交于 2019-12-07 07:28:48
问题 I am trying to write a simple physics simulation where balls with varying radii and masses bounce around in a perfectly elastic and frictionless environment. I wrote my own code following this resource: http://www.vobarian.com/collisions/2dcollisions2.pdf and I also tested the code from here: Ball to Ball Collision - Detection and Handling QUESTION EDITED With the help of Rick Goldstein and Ralph, I have gotten my code to work (there was a typo..). Thanks so much for you help. However I am

Ambigious OpenGL Default Camera position

风格不统一 提交于 2019-12-07 06:58:58
问题 in my Opengl programs (before i apply perspective projection matrix) whenever i draw some object I draw it at the origin of the world coordinate system, however almost all of the Opengl tutorials states that the camera (My projection view) is located at the origin looking toward positive z-axis (which depends on how you treat z value in the projection matrix later on), however if that is true how does my camera (located in the origin) is able to view an object located in the origin. Note: i

DirectX Math function confusion

微笑、不失礼 提交于 2019-12-07 01:02:27
While I was going over some older DirectX code, I came by the functions D3DXVec3Transform and D3DXVec3TransformCoord. Upon looking up the descriptions for them, they seemed rather similar but I don't see what the difference between the two are. Can someone please explain what is the difference between D3DXVec3Transform and D3DXVec3TransformCoord are, along with the math behind them? When you transform a 3D vector by matrix it results in a 4D vector where w!=1 a 3D vector can be described as 4D vector where w=1. D3DXVec3Transform returns the 4D vector where w!=1. D3DXVec3TransformCoord gets the

Make objects inside a group collide with themselves in Phaser.io?

大兔子大兔子 提交于 2019-12-06 13:03:16
This question is regarding phaser.io. Can someone show me how to make objects inside a group collide with each other. Right now when i do, //board is the group and it has many elements //Floor is where all the elements fall to game.physics.arcade.collide(this.board, this.floor); All the elements inside the group stack on top of each other when they hit the floor at the same position. In other words the stack builds at one position, the latest one hiding the previous element and not upwards in the sense one on top of another at a higher position. How can i make the stack build upwards? If you

Friction in SpriteKit

此生再无相见时 提交于 2019-12-06 12:23:38
问题 I'm working with Swift, SpriteKit and Xcode 6, I have a circle node on my screen and I can change the node's position with my finger, but I would like to implement a friction effect to this node, but I don't now how to do so, here's my code : class PlayScene: SKScene { let firstCircle = SKSpriteNode(imageNamed: "Circle") // theses 3 variables allows me to move the node according to my finger, but my finger don't have to touch the node var departCircleLocation = CGPoint() var

Nodes in a Scene from different layers will not interact

痞子三分冷 提交于 2019-12-06 10:53:26
问题 Apologies in advance as this Question involves allot of code. I have a GameScene with multiple layers holding Nodes/SpriteNodes for HUD/Scores/ etc. One layer, LayerProjectile, holds a Weapon Entity. Said Entity has both Sprite and Physics Components. Problem is the Projectile nodes in the LayerProjectile do not interact with nodes in the main layer (worldLayer), of the GameScene. All physics bodies are dynamic, and the GameScene has its PhysicWorldDelgate class GamePlayMode: SGScene,