Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with dynamically moving a sprite along a curve
Hello guys. I am having a scene with a 2d sprite where i am creating dynamically a CatmulRom curve.Everything is just fine except the sprite orientation.So when i start creating the curve from the front side of the sprite where the sprite up vector is, it moves and orients just as it suppose to, but when i start creating the curve from the other side the sprite moves just fine, but comes out flipped in the opposite direction of the curve's tangents.I am moving and rotating on the same principle exposed in SpriteWalkerDistance.I am using as i said a CatmulRom curve with Orientation set to tangents, No CP rotation, Initial Up Vector - Control points.Can you help me understand what is happening?Thank you in advance

Could you provide some screenshots or an example scene please?
You can see on the second picture how the sprite starts moving flipped.This is when i start drawing spline behind its tail.
Ok, looks like the tangents flip once you add CPs behind the sprite, right? I can't think of a way this could happen unless you flip the spline's direction, but I'm sure we can sort this out. How do you exactly add new CPs?

Is it possible to export this behaviour as an example scene (either posting it here or by mail to jake (at) fluffyunderware (dot) com)?

Problem solved by mail:

The easiest way to orient a 2D sprite to a spline path is

transform.rotation = Quaternion.LookRotation(Vector3.forward,spline.GetTangentFast(tf));


Possibly Related Threads…
Thread Author Replies Views Last Post
  Autogenerate bezier curve with a given direction AnAsianPanda 3 254 08-06-2021, 09:08 AM
Last Post: _Aka_
  get a point on the curve a distance away from another fortune53 1 502 03-31-2021, 07:46 AM
Last Post: _Aka_
  How to add a new point with a smooth curve? athos_k 4 1,000 03-22-2021, 09:10 AM
Last Post: _Aka_
  Get nearest point problem Lupp_ 15 2,354 03-06-2021, 12:24 PM
Last Post: _Aka_

Forum Jump: