Tag Info

New answers tagged

1

First calculate the line equation (the laser direction) <x,y,z> = <x0,y0,z0> + t*V (1) where V is the direction Vector, and is the a known position of your bullet. Second calculate the equations of each side of your entity, the intersection would be the point that satisfies (1) and one of the rectangle sides equations


0

You are asking about collision detection. Make certain you try learning 2D first, and there are plenty of youtube and wiki tutorials for you to find. As an example, imagine Mario is represented by a rectangle with position and size. A fireball can also be represented by a point. Then you can check each frame like this: if(fireball.x > mario.x ...


0

Before I answer this question here's a quick idea of how I would go about implementing an infinite or endless runner. I have worked on a couple of endless runners and they have both worked in the same way. This isn't necessarily the only way to do it but it is a way that has been proven to work. You can create generic sections of a level that contain ...


0

transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime); You do know that if the target's position is on the ground, then your object's position will also try to match the objects's Y position. You can try to make an object and check all the constraints, and it will still work if you give it a ...


1

Here's one very simple way to do it: package; import flixel.FlxG; import flixel.FlxSprite; class Player extends FlxSprite { public static inline var VELOCITY:Float = 4; public function new() { super(); // enforce subpixel-rendering for smoother movement pixelPerfectRender = false; } override public function ...


0

Let me put this simply. (Or I will try to) First of all, you should read up on Vectors, find out what these are: Vector Magnitude; Vector X,Y coordinates; Normalised Vector; After this, you should read up a bit on physics, especially Newtons three laws; kinetics; momentum; and collisions. After a week or so you should start to understand these ...


0

So I started writing some code for you. Then when I tested it, it didn't have the desired result. Here is the code so far. If anyone know what is wrong with it, do tell :-) /// <summary> /// Adds the velocity to simulate throwing a ball /// </summary> /// <param name="angle">The angle of the throw along the z axis</param> /// ...


0

It kinda depends on what you're making. If you're making a game about physics, you could conceivably write your own physics engine, however I do not recommend it. There are many 2D and 3D physics engines already out there that you can use that will save you months of work. My first time using Box2d was intimidating, and I'll admit it has a fair learning ...


2

This is fun! The trajectory is just a bunch of mathfz and a line renderer. Check out this post for more information on that which details how to calculate the trajectory. Line renderers are definitely your best bet for visualization. Even on mobile, 5-10 line renderers would be no problem. The alternative would be to hard-code the visualization with a ...


0

Like both answers said, there are 2 "secrets", one is you need to stop applying gravity when bounces are determined to be over (which is a bit of an extension over Leftium answers, he just said "resting" which is not enough because you rest as soon as you touch by this definition). Secondly, check for speed, obviously. This later condition is in relation to ...


0

Stop applying (the gravity) force after reaching RESTING_CONTACT. My guess is your sphere is reaching resting contact, but gravity (or other forces) causes it to continue moving as soon as the next update happens. Explanation: Generally, once an object reaches resting contact, it should not respond to forces until there is a force large enough to "push" ...


5

It depends on the effect you are looking for. If you are looking for a constant gravity the answer is: object.AddForce(((Vector) sphere.center - (Vector) object.pos).normalized * gravityForce); If you are looking for a gravity based on the distance between the object and the sphere then you replace gravityForce with this formula: gravityForce = ...


2

You simply need a reworked Newton's law of universal gravitation. So F=G(M1*M2)/R2 translates as code into. // Create force scalar based off of distance. distanceSquared = (gravityCenter.y - object.y)^2 + (gravityCenter.x - object.x)^2 force = gravitationalConstant*distanceSquared // Get direction from object to gravity epicenter. direction = ...


0

Instead of checking the distance for a resting contact, check for velocity. If 2 objects are moving slowly and hit each other, they should be put to rest. If not, they should do what they would do if they weren't resting. So... if (CollisionDetection()) { if (sphereVelocity.GetMagnitude() <= .1f) { //NoGravity(); //NoForces(); ...


0

First, you need to know the screen bounds: int screenHeight = getScreenHeight(); int screenWidth = getScreenWidth(); Then, you have to initialize the velocity vector for your bouncing square. In this example it'll be <1,1>: BouncingSquare bouncingSquare = new BouncingSquare(); bouncingSquare.velocity.x = 1; bouncingSquare.velocity.y = 1; Also, for ...


0

To keep a character level with a moving "ground" without its x position being affected by the physics engine, it would seem the best solution might be to place an SKConstraint on the character. Specifically: character.constraints = [SKConstraint.positionX(SKRange(constantValue: 0.0))] If you have any weird bugs from SpriteKit's physics engine, you might ...


1

Your density calculation is correct. Either the weight of the human is too much, or you have got to make the human bigger. In real life your human would have more volume or less mass. Which one to select is entirely up to you. And since this is top-down, you can expect to get the wrong density of the human with that formula. If it was a side view game, it ...


1

This is an effect of the joint-solver that tries to keep the joints together but fails to do so when big forces are applied. This occurs frequently when a "rope" consist of a large amount of small individual elements and joints. Things you could do to improve the behavior: reduce the amount of joints in your rope. Example: Create a physics-chain with ...


1

Unity's collision detection is discrete so if an object passes through another object within 1 simulation frame, the collision will not be detected. If the collision is already detected, however, forces should push the objects apart and prevent a pass-through. You can adjust the physics settings to make Unity's physics respond more accurately to collisions, ...



Top 50 recent answers are included