New answers tagged

1

This question still comes up on Google and I came up with a neat way to solve interpolating the location during a collision, so I am posting here in hopes it will help someone else stumbling here. This is based on a physics system as explained in the Gaffer on games blogs, where you have an accumulator and interpolate positions between the steps. ...


0

Near Clip Plane It sounds like you've misunderstood what a camera's near clip plane is. The official unity scripting manual describes the clip planes as: Clipping Planes: Distances from the camera to start and stop rendering. Near Plane: The closest point relative to the camera that drawing will occur. These planes create the camera's view frustum. The ...


1

Do your entities both use box colliders? When two axis-aligned box colliders collide, then there isn't really a single collision point but rather a collision line on which the colliders touch. Unity is supposed to return multiple collision points in such a situation. That's why Collision2d.contacts is an array and not a single value. But your code only ...


1

You need to pass false for the infinite_inertia parameter of move_and_collide. From the docs: If infinite_inertia is true, body will be able to push RigidBody nodes, but it won’t also detect any collisions with them. If false, it will interact with RigidBody nodes like with StaticBody.


1

Torque is just a rotational version of the same principle as linear impulses: Let us look at F = ma To compute the change in velocity, we change it to a = F/m Likewise we can say: T = Iw Where T is torque, I is inertia, and w is angular acceleration. Let's rearrange that: w = T/I Now we can use torque to compute the change in rotation. However, ...


1

Directly manipulating the velocity of a RigidBody in _physics_process is not supported. From the docs: The body’s linear velocity. Can be used sporadically, but don’t set this every frame, because physics may run in another thread and runs at a different granularity. Use _integrate_forces as your process loop for precise control of the body state. You ...


0

I share some code which will help you out: public float force = 5; public ForceMode forceMode = ForceMode.Impulse; private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Enemy")) { Debug.Log("Collision"); health -= 20; //Check for death if (health <= 0) { ...


1

You can access all project settings through the ProjectSettings object. Note that the effective gravity on an object may be different from this value, as Areas can override gravity. You can access the gravity affecting an object at a given point in time via PhysicsDirectBodyState.total_gravity. PhysicsDirectBodyState can be accessed from _integrate_forces ...


1

Forces are directional, so if you want to decelerate an object by using rigidbody.AddForce, you need to do that with a force vector which goes in the opposite direction of the current velocity. The easiest way to obtain such a vector is by multiplying rigidbody.velocity with a negative value. For example, if you want to add a deceleration force which reduces ...


0

It sounds like you already understand the solution: Keep iterating. When the swept test intersects an object, reflect it, and perform a second sweep along the new direction and remaining distance. This remaining distance only decreases with each bounce (especially if you apply a small skin offset to prevent tunnelling), so this will terminate eventually. ...


0

Well, you need to know the time to collision. Then negate it from the simulation time: and pass new velocity with new time to the 2. So you will check the collisions along the reflection vector and still simulate collisions until the simulation time is 0. The step 2 should look like: while (time >= some_tiny_epsilon_as_close_as_possible_to_zero) { ...


1

A Hashset is a collection that can't be sorted and cannot contain duplicate values, making it ideal for checking for duplicates especially due to how values are stored in memory. It checks for equality first by calling GetHashCode(). Which is a method that all objects in C# implement, if you don't override it yourself it'll use the default implementation. ...


2

Normally you want to initialize default values of your member variables in the Constructor itself it will be the faster way since UE4 uses CDO, however if you want to get a reference/pointer to another component you shall do it in virtual void BeginPlay() because at the time your constructor is called the other component/actor/whatever object may not yet be ...


1

I'm going to answer my own question here, since I figured it out. A Player's input is passed into AddMovementInput, which then affects ControlInputVector. A MovementComponent then queries this ControlInputVector using GetPendingInputVector. It then uses the result of this to update/affect Acceleration. The various Phys functions within MovementComponent ...


1

Are you aware of the PointEffector2D component? I believe that is exactly what this is for. See this tutorial (step 7). (Link directly to video)


0

You can't use the Unity gravity system for point gravity sources. As mentioned by the answer by Ed Marty, you can use the PointEffector2D component to create a point gravity source, but only if all your rigidbodies have the same mass. But you can also very easily build your own gravity system. Here is an example script for a "Gravity Source" component. ...


1

As DMGregory pointed out, you can make transform.Translate ignore the rotation of the object by passing Space.World as the second parameter: transform.Translate(Vector2.left * speed * Time.deltaTime, Space.World); However, you generally should not manipulate the transform of an object directly when that object also has a non-static and non-kinematic ...


0

When you have a question about how the Unity API works, please take thirty seconds to consult the documentation: public void Translate(Vector3 translation); public void Translate(Vector3 translation, Space relativeTo = Space.Self); Description Moves the transform in the direction and distance of translation. If relativeTo is left out or ...


2

If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. As explained in rigidbody documentation page, when the property isKinematic is set to true, collisions won't be checked anymore. There is something important to understand: the role of the Rigidbody and the one of the Collider. Rigidbody gets all the Physics ...


1

Moving on a single axis is just incrementing the value of the relevant axis in the position vector by the relevant distance. So just do (pseudo code here, because I'm not near my Unity machine) if (shouldMoveOnX(followerPos, myPos) { followerPos.x += step; } else { followerPos.y += step; } The only question is how to determine 'shouldMoveOnX' - and in ...


1

I understand the local need (moving from rolling waves to breaking waves), but as I can't figure out the larger need (how the game will evolve around this) my answer might just be out of place as highly theoretical. But let's try it. Have you considered using approach3 but only on small patches of your mesh? You have that mesh of yours with small waves on ...


-1

You can use a shader to achieve the effect. Unity's new "Lightweight Rendering Pipeline(good for Mobile) supports "Shader Graph"; so you can use "shader graph" to create good looking wave, you can use change values of the material to control the wave and other stuff. This tutorial can be a good start!! https://www.youtube.com/watch?v=FbTAbOnhRcI


2

You can view the particle system settings in the inspector and check on the collision box and specify what it should collide with. The first spell that hits normally is because the two collide. The second spell needs to have collision added to the particles since the transform is not actually near the enemy to perform a typical collision.


Top 50 recent answers are included