08-14-2024, 05:45 AM
(This post was last modified: 08-14-2024, 08:05 AM by wallflower6.)
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).
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.
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!
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!