Tag Info

Hot answers tagged

9

I was going to write this as a comment, but it ended up being rather long winded so I've turned it into an answer. The current answers are mostly correct, but a few things mentioned are misleading/wrong. In general, most game-play related tasks will go in Update. For example, you don't want to be polling for input in FixedUpdate (not because of ...


6

What you're doing sounds a lot like premature optimization to me. Did you try using the physics-engine and did it actually turn out to cause performance issues? If you don't need the physics-simulation and just care for the collisions, why not use sensors (or "triggers", as they are called in Unity). For stationary objects, use a collider with the Is ...


5

You should read up on Speculative Contacts for catching when collisions will happen before you end up with this kind of penetration.


5

This code is taking the collision between two spheres and moving them based on their masses and velocity. Here's a really basic illustration to show why there is penetration between a blue ball and a green wall. In this example the center of the ball is 5 feet from the edge of the wall. The ball is moving at 1 foot per second and you are running at a ...


5

I think your problem comes from multiple collisions. Consider three spheres A, B & C. A sits there. B hits A. Fine. C hits B. B is nudged into A. Oops.


4

The documentation isn't terribly clear on it—and I'm not currently in a position to verify it—but I believe that the force applied from RigidBody.AddForce() (link) is applied at that object's root location (at its transform.position). If not at transform.position, then at the object's RigidBody.centerOfMass (link). If you want to apply a force ...


4

I think the crucial part of this question is how you can procedurally generate stable structures (as generating an unstable pile of blocks in real time should be no problem) My approach would be to prebuild sub structures that are guaranteed to be stable. Have each substructure store two sets of spans" * one for the bottom where it requires contact below ...


4

I'm not sure but maybe you can connect both balls with an spring. if you don't want those two to change their distance you can put a very high value for spring constant. although this way the second ball also will effect on the first ball movement.


4

Blender 3D is open source, and free. It is a modeling and rendering application, but it comes with easy to use soft-body, fluid, and ridged-body physics solvers. You could set up a number of slightly different simulations, that match the dimensions of the area in your game, and export the animation data from blender to use in your engine. In the game, ...


4

An impulse is an instantaneous change in velocity. You can calculate the velocity of a point before and after an impulse has been applied to the body. The velocity of a point is: V = Vcm + omega cross r V is the velocity of a point on a rigid body. Vcm is velocity at the center of mass. Omega would be angular velocity, and r is the vector from center of ...


4

Your solver needs multiple iterations (aka sequential impulse) over its contacts. Treat each contact point independently and calculate the impulse to resolve its contact constraint for that iteration. This may cause previously resolved contact points to be pushed back into the colliding object, but not by as much as the initial penetration. Perform ...


4

You seem to be answering your own question in your "question", and it seems to me like you are asking for clarification. Please note that my answer is Unity specific. Why use Rigidbodies? When you use a rigidbody, then you should use a rigidbody. Allow me to explain what I mean. Often times, when I see developers using rigidbodies; they are neglecting its ...


4

The Update function is called every frame. Its frequency depends on how fast the computer is able to render images. On a slower computer, Update is called less frequently than on a faster one. If you do time-based calculations, you can normalise them using Time.deltaTime which tells you how long it has been since the last time Update has been called (caveats ...


4

First of all, since you're working in 2D, you'll want to use the type RigidbodyConstraints2D as opposed to just RigidbodyConstraints. Secondly, you can't freeze the y rotation on 2D rigidbodies, only in the z axis, which you can do by saying: pos = RigidbodyConstraints2D.FreezeRotation; Equally, you could just set it in the inspector with the gameobject ...


3

Thought I would post it as an Answer. When wanting to manipulate a RigidBody, You need to take into account the given Physics when Not-Kinematic. Many time in Games Dev there are 2 ways to Code Physics, Either follow the laws and implement them OR, fake the effect. A lot of things that go wrong in Unity is when Realistic Physics meets, Fake mimic. Both ...


3

This article ("Advanced Character Physics" by Thomas Jakobsen, with a PDF mirror here that preserves images) discusses solving fixed distance constraints (which sound to me like your fixed joints) between particles by relaxation -- specifically you want the section "Solving several concurrent constraints by relaxation" on page 2, I think -- treating the ...


3

The usual tricks with weapons are: Make your character's collider large enough that it contains your weapons, then simply ignore collisions between it and the weapon's raycasts. Make it appear not to go through by drawing it on top of other objects. This works for FPS type games: Put the weapon(s) on a new layer (for this example it will be named ...


3

One major advantage is that many collision detection operations are more efficient when performed at the origin. A classic example is box vs sphere. When done in a box's local space the tests are very simple axis aligned distance point-plane tests instead of the more costly non-axis aligned planes. Furthermore objects moving through space may not actually ...


2

You could 'cheat' the system.. An 8 sided die only has 8 possible values. If you randomly pick a number you could then play 1 of 8 animations that end on the number that was randomly generated. You would not get it to look like a random roll every time, but it would roll to a randomly generated number. A second step to the canned animations would be ...


2

Rather than building a solid object for your tentacles, I would suggest instead using a single linear chain — a 'skeleton' for the tentacle — and then procedurally wrapping a descending sequence of trapezoids around it, out to the tip. Use the local orientation information to define crossbars at each vertex (e.g., normal to the average or ...


2

Transform.position on a rigidbody won't do any collision checks and just costs more performance. Applying force to a rigidbody will move it while checking for collisions and such in a realistic sense. Things like moving up and down a ramp will be faster and slower (because of the direction of force) you could get around this by changing the direction the ...


2

To find a good algorithm for such a stance will take quite some time, observation and testing, I don't think you will find a "one-fits-all" solution on the internet. There is a lot you have to consider for skeletons climbing obstacles and I assume you don't only want it to take a certain stance, but to move from one to another in a realistic way. "Specific ...


2

Tentacles work in nature (and robotics) because of muscles inside, this means that each segment or three is only locally affected by a small number of forces. It sounds like you have a setup where all the force starts at the base and propagates outwards, which gets you a whip instead of a twisting tentacle. You may want to build a system with small forces ...


2

Add a character controller and use controller.move() with this you can make your character don't walk through the walls, if this wall have a collider.


2

The direction of the force applied to a point colliding with your rotating object is the tangent to the sphere, perpendicular to the axis the sphere is rotating on. You should be able to calculate it with the following pseudo-code: vectorToContact = (pointOfContact - centerOfSphere); directionOfForce = normalize(cross(vectorToContact, axisOfRotation)) A ...


2

I think if you change the last line to this it should work. r.AddForce(Vector2(px, py).normalized * EXPLOSION_FORCE / Vector2.Distance(r.transform.position, transform.position)); normalize sets the vector to be length 1, then you multiply by some force and divide by the distance, so the further away it is, the less force is given.


2

From: http://unity3d.com/learn/tutorials/modules/beginner/scripting/update-and-fixedupdate The time-step used in FixedUpdate is not variable. If your game starts to lag, when it catches up, you don't want >10seconds of physics in one update, so it is typically done in FixedUpdate which is called on a fixed-interval. For example: Update(float ...


2

Update is called as fast as possible. The variable 'Time.deltaTime' is set to the actual amount of time that passed since the last call. If lag or something similar slows down the game, Update will still be called only once once the lag is over, with a high value of deltaTime. FixedUpdate is called at regular intervals. It will never be called more often ...


2

It looks like these two lines are overriding the velocity-based movement from the RigidBody: LillyRB.MovePosition (LillyRB.position + (transform.forward * movever)); LillyRB.MovePosition (LillyRB.position + (transform.right * movehor)); Generally when combining player/AI control with Rigidbody physics, you'll want to use forces & accelerations to move ...


1

I'm guessing this is due to the collision resolution. Gravity pulls your character down and you start penetrating the slope. The collision is resolved along the slope normal, so you move out diagonally. Each frame the character moves down from gravity, and out slanted. You can imagine that since the resolution is slanted and gravity is downward, over time ...



Only top voted, non community-wiki answers of a minimum length are eligible