Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving object along spline close to player
#7
Hiya again!

Sorry for the bother but I'm running into a weird issue with GetNextSegment and GetPreviousSegment I'm at the point where I'm trying to get the player attached to the box and I want to rotate them around the ledge by being attached to the box. 

Currently if I use GetPreviousSegment it works fine and my character spins around the box at light speed in the reverse direction, skipping CP0
If I do GetNextSegment however, they make it to CP0 and then it just stalls and the character won't move around anymore.

I tried using GetNextControlPointUsingFollowUp as well but it still got hung up on the same spot

Apologies for the spaghetti code I was planning on cleaning it up much more once I got it actually working haha

Code:
IEnumerator ShuffleLeft(float waitTime){
    var lookPos = transform.position - player.transform.position;
    lookPos.y = 0; //lock
    if (lookPos != Vector3.zero){ //need this to fix an error being spammed
    var rotation = Quaternion.LookRotation(lookPos);
        }
    nearestTF = Spline.GetNearestPointTF(transform.position, Space.World); 
           
    nearestTFSegment =  Spline.TFToSegment(nearestTF);
    CurvySplineSegment nextSegment = Spline.GetPreviousSegment(nearestTFSegment);
    float nextTF = Spline.SegmentToTF(nextSegment);
    Debug.Log(Spline.GetNextControlPoint(nextSegment));

        Quaternion nearestOrientation = Spline.GetOrientationFast(nextTF, false,Space.World);
        transform.rotation = nearestOrientation;
   
        ledgeHitBoxPosition = Spline.Interpolate(nextTF, Space.World);
        transform.position = ledgeHitBoxPosition;
 
    player.transform.position = new Vector3(ledgeHitBoxPosition.x,ledgeHitBoxPosition.y-1.185749f,ledgeHitBoxPosition.z);// moves the player vertically into place
    playerNearestOrientation.Set(player.transform.rotation.x,nearestOrientation.y,player.transform.rotation.z,1);
    lookPos = transform.position - player.transform.position;

            rotation = Quaternion.LookRotation(lookPos);
            player.transform.rotation = Quaternion.Slerp(transform.rotation,rotation,0f);
            player.transform.Rotate(11,-90,-180); //rotation offset
            yield return new WaitForSecondsRealtime(waitTime);
            shuffling = false;
}

--Edit-- nevermind sorry for the bother but I managed to get it working in a very silly way by taking use of the built in spline controller to handle smoothly moving it works now! if you have a better way that i should have done it i still would like to hear tho
Reply


Messages In This Thread
RE: Moving object along spline close to player - by minaa - 12-26-2021, 07:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 14 03-04-2024, 11:06 AM
Last Post: _Aka_

Forum Jump: