Advertisement
mew_fi

Spring damping

Nov 28th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.47 KB | None | 0 0
  1. void OnCollisionStay(Collision col) {
  2.     usedforce = Mathf.Clamp(force - force * rangechange * damping, 100, force * 2);
  3.  
  4.     direction = tform.position - targetPos.position;
  5.     player.AddForceAtPosition(direction * usedforce, targetPos.position);
  6. }
  7. void FixedUpdate () {
  8.     range = (tform.position - targetPos.position).magnitude;
  9.     rangechange = oldrange - range;
  10.     oldrange = range;
  11.        
  12.     body.AddForce((targetPos.position - tform.position) * speed, ForceMode.Acceleration);
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement