- Home /
Making rigidbody dynamically transform instantly after applying force to it
So I've been stuck on this problem like forever, almost a month if you asked me. I have this magnetic field behavior I want to replicate, where user can play with the so-called metal rod to react with the magnetic field and observe the changes in pattern of the magnetic field, the function is working, but I don't know how to make the cube which holds the point of contact to react instantly, which is no bounce on collision, and also I want immediate drop after the metal rod is removed from the field.
I tried to reduce the bounciness by increasing the drag on the cube below, but it slowly drop on its original position, which is not the effect I wanted. Any ideas?
The code I've been working on to apply the effect
private void Attract(Rigidbody rb)
{
float Distance = Vector3.Distance(rb.transform.position, maxBounds.transform.position);
float TDistance = Mathf.InverseLerp(MaxRange, 0f, Distance); // Give a decimal representing how far between 0 distance and max distance the object is.
float strength = Mathf.Lerp(0f, MaxStrength, TDistance); // Use that decimal to work out how much strength the magnet should apply
Vector3 FromObjectToMagnet = (maxBounds.transform.position - rb.transform.position).normalized; // Get the direction from the object to the magnet
FromObjectToMagnet.x = rb.gameObject.transform.position.x;
FromObjectToMagnet.z = rb.gameObject.transform.position.z;
rb.AddForce(FromObjectToMagnet * strength, ForceMode.Force);// apply force to the object
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612182835im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Editor drag&drop override 1 Answer
Algorithm for Finding Shapes on a Grid 1 Answer
dragShot script mod 0 Answers
Drag rotation problem 0 Answers
Event.DragExited returns wrong Event.mousePosition 0 Answers