14

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 ...


8

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 ...


7

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 ...


6

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 ...


5

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 ...


5

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 it....


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

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

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 ...


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 ...


4

4 member variables that persist between calls to Update: //Movement public float speed; public float jump; float moveVelocity; //Grounded Vars bool grounded = true; In Unity, Update() is called on a MonoBehaviour once per frame: void Update () { This detects the four different jump buttons: //Jumping if ( Input.GetKeyDown (KeyCode.Space) ...


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

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.


3

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 ...


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

You could use both, depending on case and need. Both are valid and both occur together. The difference in your case is apparently how you define loss of energy, ie. what is more convenient and accurate. In case of momentum, we have P=mv, and you can only work with v; in practice only with elastic collisions. Here is the classic example of (indestructable) ...


3

It is a general property of rigidbodies that theier inertia tensor can be diagonalised. This means it can be reduced to a form [I1 0 0] [0 I2 0] [0 0 I3] This is why unity and physx do not deal with the products of inertia. It is likely that, for whatever problem you are trying to solve, it is simpler to do some rotations of your axes (in order to obtain ...


3

The drag movement is not being applied through a force on the rigidBody but directly on the object's transform position, so what you are trying to do wont work. Instead you need to detect the collision and then disable OnMouseDrag with a boolean value sort of like this: bool allowDrag = true; void OnMouseDrag() { if(allowDrag) { //... do ...


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

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

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

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

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

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

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 ...


2

From here, this can be used to calculate the volume of an arbitrary 3D mesh. public float SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3) { float v321 = p3.x * p2.y * p1.z; float v231 = p2.x * p3.y * p1.z; float v312 = p3.x * p1.y * p2.z; float v132 = p1.x * p3.y * p2.z; float v213 = p2.x * p1.y * p3.z; float v123 = ...


2

You are changing its velocity using the AddForce method. This adds a force, not a velocity to the body. The change of velocity happens the next time the rigidbody physics are processed by the game engine, which happens during the next FixedUpdate.


2

If you want realism, you should consider that on impact kinetic energy can be transformed in a few different ways. It can cause movement, or be converted into other forms of energy, usually by deforming/damaging the objects involved in the impact. Assuming that when two objects collide they bounce away in some manner, you could base damage on the loss of ...


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