Translate in the same time ?

Hi Everyone,

I would like to know if it’s possible to use a lerp and a translate in the same time. Here is my problem : I have my object (A for exemple) and I use a transform.translate to move this object in the forward direction on the Z axis. My object must avoid another object (B for exemple) to his left and to avoid this object B, I use a lerp in a coroutine but the problem is that the object A continues to straight forward and when using the lerp to avoid the object B my object A rollbacks because the position on the Z axis is not updated.

The object A continues to forward during while the lerp is carried out what causes rollbacks.

To solve my problem, I need to do a diagonal move with the lerp and calculate or update the position of the object transform on the Z axis of my object A. But I have no idea if it’s possible or not. So I tried some other solutions such as for example pre-calculating the position of the object A in the Z axis in the lerp but here too, I don’t know if it’s possible because I tried but I failed.

I appreciate your help if you have any leads or ideas to help me :slight_smile:

Hi, I’ve resolved my problem.

I think I’am just tired, It’s time to do a break … :stuck_out_tongue:

I use Mathf.Lerp rather than Vector3.Lerp to move just the X position of the object.

It’s obviously possible. The real question is if it a solution for what you are trying to do, and you seem to realize that something is off.

In cases like this I find it helpful to go back and try to unpack the goal. You are probably trying to do two things at once, and by the look of it, you are trying to graft the solution for the second onto the solution of the first (probably because your code evolved that way).

You see to try to accomplish the following:

  • Move an object from A to C
  • Avoid an obstacle B that may be in the way

Simply lerping the vector A–>C (probably your initial solution) doesn’t play well with avoiding obstacles.

While you can probably brute-fore a solution that works for this instance (maybe perform an additional avoidance lerp in the opposite direction of A–>B, controlled by distance), you may want to look into more generalized appoaches.

A comparatively easy solution may be a nav agent that automatically avoids object obstacles and still maneuvers the closest possible route A–>C, and it takes only a couple of minutes to set up (plus about 30 minutes reading up on how they work: baking nav meshes and static objects)

1 Like