game-physics

How to get the vector direction between two (p1, p2)?

女生的网名这么多〃 提交于 2019-12-11 20:09:25
问题 I have been working on Unigine and been trying to code a flight program for weeks, I need to find the direction between two dummy nodes so I can use this direction to rotate the wings of the aircraft. Any explanation would be appreciated. 回答1: First you have to calculate the length of the distance between P1 and P2. distance = abs(P2(y) - P1(y)) Then you can use the angular functions to calculate the angle. a = sin(distance / length(P12)) 回答2: If under the direction you mean angle w.r.t. an

How to improve/fix collision detection between ball and paddle?

大城市里の小女人 提交于 2019-12-11 19:07:32
问题 Basically i am in the process of making a game which is like pong, breakout, etc. I am having some problems when the ball and paddle collide... but only sometimes! This video here is what is occuring: http://www.youtube.com/watch?v=uFZIxFIg0rI So yea, basically the ball sometimes seems to go a bit crazy when it collides with the paddle... normally if i am moving the paddle in the opposite direction of which the ball is approaching it. Also the ball sometimes get's caught between the bottom of

Adding a new enemy every x amount of seconds - Android Game Dev

泪湿孤枕 提交于 2019-12-11 17:53:11
问题 I have been following along with the tutorials from: http://www.edu4java.com/en/androidgame/androidgame.html Where I stand now is that I am able to populate the screen with a variety of sprites and each character will begin at a random position and they will walk in a random direction. My objective is to add a new sprite every X amount of seconds but I am not entirely sure how to do this. Currently my GameView is set up like this: public class GameView extends SurfaceView { private

Cocos2D Sprite Relative Movement

夙愿已清 提交于 2019-12-11 15:24:22
问题 I have a problem that I can't seem to solve. I would like to move a sprite on the screen based on finger movements, but instead of making the sprite move towards the touch position I would like the sprite to move in the same way the finger moves on the screen. Example: User puts his/her finger on the screen (any position) and then drags the finger on the screen by 200 pixel to the left, the sprite should also move of 200 pixels to the left. My approach was to store the position of the player

Drag 3d object using fingers in unity3d

喜欢而已 提交于 2019-12-11 11:12:10
问题 I create a scene has an AR camera and a 3d object. When application starts, I see the object on the screen. I want to move this object using fingers. I tried many codes. But I couldn't find a nice solution for me. AR camera is tagged MainCamera . I use below code, and the result is unexpected for me. I click on object and the console output is here: How can I move 3d object to mouse click position? I don't use any marker. Vector3 vect3 = Camera.main.WorldToScreenPoint(car.transform.position);

Why isn't my homing missile algorithm working?

拟墨画扇 提交于 2019-12-11 08:49:43
问题 I've taken code that's heavily inspired by this answer but my projectile is not homing in the way I expect. The initial projectile direction is often perpendicular to the target. At which point, it does seem to home in on his direction, but if it "passes" him, it seems to get stuck in place like it's frozen at a point but then seems to follow the movements the target makes without moving at its intended speed. I've commented a line of code that I'm concerned about. He's using V3 and V4 in his

Could not create physics body - Swift

吃可爱长大的小学妹 提交于 2019-12-11 07:44:57
问题 I have a Swift file called ChainsawMaker.swift which I want to use to create chainsaws throughout my game. When I call instances of this and add it to my game, the chainsaws and it's physics body get added to the game perfectly - except for an error that pops up in the console: "Physics Body: Could not create physics body". Here is the code for ChainsawMaker.swift: import SpriteKit class ChainsawMaker: SKSpriteNode { func longChainsawCreator2 () -> SKSpriteNode { //LONG CHAINSAW let

How do I move the Rigidbody in FixedUpdate, but still have my character be affected by gravity?

大兔子大兔子 提交于 2019-12-11 07:22:33
问题 So Below you see what I initially used to control my characters movement. _RigidBody.velocity = _ConstantWalkingSpeed * direction.normalized; This works for walking around in 4 directions. However, if my character falls over an edge, he falls veeeeeery slowly. If I then in mid air disable the walking script, gravity picks up and goes at normal speed. This leads me to believe that my movement script somehow affects the gravity effect. As such I tried this solution: _RigidBody.velocity =

Ball Mechanics - Is this the best approach?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 07:20:11
问题 Good day, I'd like to program a constantly moving ball ( object3 ) being passed between two stationary objects ( object1 , object2 ), with the ability to set the max height Y of the pass trajectory dynamically. What would you argue is the best way to program the ball physics for this concept? I've looked at using addForce on a default sphere w/ a rigidbody. It seems like there should be an equation that expresses the trajectory of a pass of object3 from object1 's x to object2 's x... at a

Unity Physics: How To Limit Rotation of Object Moved by Gravity

橙三吉。 提交于 2019-12-11 05:38:45
问题 I have a Child object, an Iron Bar (with Rigidbody and Gravity), connected to a Long Arm (w/ Rigidbody and isKinematic). I need to restrict the rotation of the Iron Bar from 1 to 40 degree angles only so it won't go overboard and hit the Long Arm . Please refer to attached image for more info. I tried several approaches from using a Hinge Joint and its Limit options and also through code. But I cannot seem to solve this problem. Right now I have this script attached to the Iron Bar but it