Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scene 51: Dynamic track between two points
#1
Hi,

I just started using Curvy and it's been great so far!

I'm trying to build a moving object (eg. a vehicle) that has a reference to two transforms - a previous location and a next location, and is able to dynamically travel from the previous loc to the next loc (which can be changed dynamically, eg. through another script). 

I have tried extending Scene 51 by modifying the logic in the E51_InfiniteTrack.cs script to direct the vehicle to the next location's position (the following code is in the addTrack method). 

Code:
// Get localPosition of last control point of spline
Vector3 p = TrackSpline.ControlPointsList[TrackSpline.ControlPointCount - 1].transform.localPosition;

// Calculate direction towards nextTransform
Vector3 targetDirection = (nextTransform.position - p).normalized;

mDir = Vector3.Lerp(mDir, targetDirection, 0.5f);

Vector3 position = TrackSpline.transform.localToWorldMatrix.MultiplyPoint3x4(p + (mDir * CPStepSize));

It works fine, however, the vehicle kept starting its movement from (0, 0, 0). Since I need it to start from a specific point, I figured I needed to modify the start CP's Vector3.zero in the setup method. I changed this to the position of the specific start point and also modified mDir, ie.

Code:
Vector3 startPosition = initialTransform.position;
mDir = (nextTransform.position - previousTransform.position).normalized;

// Add the start CP to the spline
TrackSpline.InsertAfter(
    null,
    startPosition,
    true
);

However, the vehicle's movement becomes erratic, although it does start from the specified point. And after moving in a random direction, it often gets stuck / bunched up in one spot. I'm not sure if it's due to some issues with the mDir. 

Would appreciate any help, and thank you in advance!
Reply


Messages In This Thread
Scene 51: Dynamic track between two points - by wallflower6 - 08-14-2024, 05:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Any performance 'hacks' for scene with lots of splines rickgplus 1 1,825 03-18-2025, 10:11 PM
Last Post: _Aka_
  Disable rebuild of meshes in dynamic mode Zilk1 3 2,265 05-27-2024, 08:14 AM
Last Post: _Aka_
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 3 2,947 04-02-2024, 02:24 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 1,786 03-28-2024, 10:08 PM
Last Post: _Aka_

Forum Jump: