1

My GameObject (say a cart) is moving along in some direction and at some point it needs to move in from p1 to p2, (the red spots in the picture linked below, each element) in an arch like fashion and not just straight. Like a turn 45 degree turn in the road, alt text (the game is in 3d). Top view of the movement

The available information I have is the following:
startPos (Vector3),
endPos (Vector3),
Angle in degree, I know how many degrees the turn is supposed to be. it will be 15 / 30 / 45.
Radius of the curve is 2.5

So far I have only been able to move it straight. I'm using Vector.Lerp. My math mind sucks, but I was thinking that maybe I could divide the curve into smaller bits and then just move straight between those?

Fay
  • 122
  • 4
Jacob Jensen
  • 15
  • 10
  • Plenty of solutions: https://stackoverflow.com/questions/37212184/unity3d-rotate-around-a-specific-point-over-time Key words you need: Interpoalating on a circle circumference by angle How i would solve it: Get the circle equtation then interpolate between the two points according to the speed – Menyus Mar 13 '19 at 10:16
  • 1
    theres a lovely function rotatearound... you can use this to move items in an arc – BugFinder Mar 13 '19 at 10:20
  • 1
    Damn thats even better, because already moves his transform – Menyus Mar 13 '19 at 10:26
  • I dont understand how you find the circle equation with just 2 points and a radius. I see two circles can defined from such. See https://www.quora.com/How-do-we-find-the-equation-of-a-circle-when-two-points-on-it-and-the-radius-of-a-circle-are-given – Jacob Jensen Mar 13 '19 at 10:43
  • You don't need to find the equation as @BugFinder mentions. You can just use [this](https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html) – Ali Kanat Mar 13 '19 at 11:12
  • Transform.RotateAround requires that i know the center point which i want to rotate around. How do i find this point from these informations. I know the start point, endpoint, radius + curve degree (eg 45), and whether it is a left or right turn. – Jacob Jensen Mar 13 '19 at 11:36
  • You can calculate it using `MyRedGameObject.transform.position +(-MyRedGameObject.transform.up) * radius)` – Ali Kanat Mar 13 '19 at 13:52
  • You can also use iTween to make it smoother in a lot of curves, so you can do it like accelerating or bouncing when transition it, you only need to add values and time. – Horothenic Mar 13 '19 at 15:34
  • @BugFinder as concise as that comment is: that's an answer, and should really be one so that future visitors can easily find it, too. – Mike 'Pomax' Kamermans Mar 19 '19 at 15:19
  • @Mike'Pomax'Kamermans i wasnt in the position to write a more comprehensive answer than basically "look at this function" – BugFinder Mar 19 '19 at 21:35
  • Of course you were. "You probably want to use `rotatearound` to move items in an arc, as explained over on (link to Unity3D docs page for that function" and boom: useful answer. – Mike 'Pomax' Kamermans Mar 19 '19 at 22:41

0 Answers0