Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SplineController.AbsolutePosition or SplineController.RelativePosition to WorldPos?
#1
Hi everyone,

does anyone know  how to convert the SplineController.AbsolutePosition or SplineController.RelativePosition to WorldPosition ? (for sure if a spline is set to)

After set in Update()
SplineController.AbsolutePosition = 10;
then
SplineController.transform.position  returns a value from any previous frame.

further SplineController.Refresh() doesn't update.

Or is there any Curvy command available for? (like SplineController.ToWorldPosition)


Thanks Roger
(Henry Ford) Each hour more of searching is each hour less of your live time.

Reply
#2
Let me explain:

When you change RelativePosition or AbsolutePosition of a controller, it's TF is changed. The actual position is applied to the transform in the next call to Refresh() then. To get the resulting position immediately after changing the position, use the source spline with RelativePosition, e.g. SplineController.Spline.Interpolate(SplineController.RelativePosition).

Alternatively, add this to CurvyController.cs (currently untested, but should do the trick):

Code:
/// <summary>
/// Applies the current position to the transform
/// </summary>
/// <remarks>Use this to immediately set the transform after changing AbsolutePosition or RelativePosition!</remarks>
public virtual void Apply()
{
      applyPositionAndRotation(mTF);
}

This will be added to 2.0.5
Reply
#3
Information 
(01-05-2016, 06:28 PM)Jake Wrote: SplineController.Spline.Interpolate(SplineController.RelativePosition).

Your example returns the local position of the of the origin spline position. Not the WorldPosition.

(01-05-2016, 06:28 PM)Jake Wrote: Alternatively, add this to CurvyController.cs (currently untested, but should do the trick):

Yes and no.

Yes, after Apply() the internal SplineController.transfrom.position returns the WorldPosition. Okay this is great anyway. Smile

No, the transform of the GameObject itself does not updated after UPDATE(current frame) has finished.
Example:

Code:
using UnityEngine;
using System.Collections;
using FluffyUnderware.DevTools;
using UnityEngine.UI;
using FluffyUnderware.Curvy.Controllers;
using FluffyUnderware.Curvy;

public class TestSplinePosition : MonoBehaviour {
    public SplineController Spline;
    public int f = 0;

    // Use this for initialization
    void Start() {
        Spline = this.GetComponent<SplineController>();
    }

    // Update is called once per frame
    void Update() {

        if (f == 0) {
            Spline.AbsolutePosition = 5;
            Spline.Apply();

            if (Spline.transform.position.x != 0) {
                Debug.Log("Updated to Spline.transform.position =" + Spline.transform.position.x);
            }
        }
        f++;
    }
}

1) The SplineController.Position is internally updated but the real GameObject is not!

2) After Spline.AbsolutePosition = 5;  Spline.Apply(); is executed in 2 additional  Frames (1 - 2 and 3)  then the GO will updated.

Code:
using UnityEngine;
using System.Collections;
using FluffyUnderware.DevTools;
using UnityEngine.UI;
using FluffyUnderware.Curvy.Controllers;
using FluffyUnderware.Curvy;

public class TestSplinePosition : MonoBehaviour {
    public SplineController Spline;
    public int f = 0;

    // Use this for initialization
    void Start() {
        Spline = this.GetComponent<SplineController>();
    }

    // Update is called once per frame
    void Update() {

        if (f == 0 || f == 1 || f == 2) {
            Spline.AbsolutePosition = 5;
            Spline.Apply();


            if (Spline.transform.position.x != 0) {
                Debug.Log("Updated to Spline.transform.position =" + Spline.transform.position.x);
            }
        }
        f++;
    }
}



Example:
The cube is at position 0,0,0 and the SC own position 5,0,0 while unity play.
(Henry Ford) Each hour more of searching is each hour less of your live time.

Reply
#4
Quote:Your example returns the local position of the of the origin spline position. Not the WorldPosition.
Right, Splines return local positions, always. Just transform them!

Quote:No, the transform of the GameObject itself does not updated after UPDATE(current frame) has finished. The SplineController.Position is internally updated but the real GameObject is not! 
Impossible! If you don't believe me, just add a debug log inside CurvyController.Refresh(), right below the call to ApplyTransformPosition()...

Let me guess what happens here in order when you hit play in your project:

1.) Your script sets the position => transform is set to new position (like your Debuglog shows)
2.) The controller starts playing. First, it's set to it's InitialPosition (still 0, I guess) => see the problem? If the controller isn't running, use InitialPosition!
3.) Next frame: Your script runs again, this time setting the position of the moving controller, which works like you want.

It's fine to set the controller from outside scripts, but I recommend using a well defined fixed order. Either by using Update()/LateUpdate() or script execution order.

Hope that helps,
Jake
Reply
#5
Spline.InitialPosition helps

Thanks!!
(Henry Ford) Each hour more of searching is each hour less of your live time.

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Wink In SplineController OnPositionReachedList Event is missing shimizu 2 13 02-07-2022, 12:47 PM
Last Post: shimizu
  best way to rotate, change offset, and inset position of splinecontroller object smackledorf 1 24 01-17-2022, 01:39 PM
Last Post: _Aka_
  SplineController slows down approaching connections jh092 5 2,542 08-07-2020, 03:56 PM
Last Post: _Aka_
Brick Strange thing happening when setting RelativePosition curvyuser007 1 1,253 05-17-2020, 09:34 PM
Last Post: _Aka_

Forum Jump: