use physics to hold object in place
I'm trying to give a Game object with a rigid body a 'goal' location that it will stick to. Other physics objects should be able to push it away from that point but it should always 'spring' back.
void Update ()
{
direction = goal - transform.position;
speedMod = Mathf.Lerp(0, speedEffectLimit, direction.magnitude) * speed;
rigidbody.AddForce(direction.normalized * speed, ForceMode.Force);
}
But I can't get the objects to stop overshooting their goal. Is their any other way to achieve this?
Answer by JedBeryll · Jun 17, 2016 at 08:57 PM
Use a spring joint: http://docs.unity3d.com/Manual/class-SpringJoint.html
Join one end to your gameobject, and the other to an object which it should stick to.
Your answer
Follow this Question
Related Questions
stack-type game problem (blocks fall). bloques se caen en juego de apilar cajas 0 Answers
Player Movement Goes Crazy When Hit On Side Of Moving Platform 0 Answers
Rigidbody is colliding terrain on isKinematic = false. call although meshes don't touch 0 Answers
Player (RigidBody) jitters when colliding with object and jumping. 0 Answers