How to move an object "Smoothly" away from another object?
Hey there, My game is a basic rope swinging game and I have ObjectA (The Wall) moving away from ObjectB (The Ball swinging from the rope) and then ObjectA moves back to its original position when ObjectB is no longer in the trigger. When ObjectA moves back to its orignal position, its smooth as butter, but when being pushed out of the way by ObjectB, it gets choppy, especially at highspeeds (But I need it to move at high speeds, see code below to understand). To be clear, my code is functioning completely, its just I'm looking for a sneaky trick or tip to help smooth out the "pushing away" effect, just how it is when it returns to BaseWallPosition.
void Update() {
if (BallInTrigger) {
target.position = Vector2.MoveTowards(target.position, new Vector2(transform.position.x, BaseWallPosition.y), -1 * rb.velocity.magnitude * Time.deltaTime);
}
else {
target.position = Vector3.MoveTowards(target.position, BaseWallPosition, WallMoveSpeed * Time.deltaTime);
}
}
void OnTriggerStay2D(Collider2D col) {
if (col.tag == "Wall") {
BallInTrigger = true;
}
}
There is obviously alot more to this code, but this is the important stuff to the issue
Your answer
![](https://koobas.hobune.stream/wayback/20220612222333im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Everything in the scene except the player looks blurry when the camera is moving | Unity2D 1 Answer
Move a Rigidbody by a specific certain amount in a smooth motion? 2 Answers
Accelerate float rather than decelerate with Mathf.SmoothDamp 0 Answers
How to smoothly change position 1 Answer
How to make camera follow player from point to point 2 Answers