Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Begginer questions
#1
Hi all, 

I'm new user of curvy Smile

And I have some beginner questions Smile

1. How can I move object by 5 units on spline? (i need to make patrol agent that he moves by specific distance on spline)
2. How can I change splines smarter way than entering on trigger? 

Thanks for any help Smile
Reply
#2
Hi Szagi,

1.) Use a SplineController and set it's movement to "Absolute". Speed then means units/second. Enable Animate and set the animation properties if you want a one-shot or tweening behaviour.

2.) I don't understand that, can you please elaborate what you're after?
Reply
#3
Sorry for my bad explanation

1.) I didn't understood this well Sad Animate property can be use for this: my enemy moves for example 5 units, than stops, then change direction and moves 8 units? 

2.)  http://imgur.com/HAjeUPX vertical wall is my trigger which changes splines from down spline to upper spline, but this is a bit jumpy and I have no idea how can I do it smoother Sad

this is my code: 

Code:
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player"){
PlayerSplineController wagon = other.GetComponent<PlayerController>().Wagon;

//TODO:  changing splines is good thing to move to SplineManager
if (wagon != null) {
_enterDirection = Mathf.Sign (wagon.Speed);
Vector3 nearestPoint;
float nearestPointTF;
Transform newParent;
CurvySpline newSpline;

if (direction && _enterDirection > 0 || !direction && _enterDirection < 0 ) {
nearestPointTF = nextSpline.GetNearestPointTF(transform.position,out nearestPoint,7,8);
newSpline = nextSpline;
newParent = nextSpline.transform;
} else {
nearestPointTF = prevSpline.GetNearestPointTF(transform.position,out nearestPoint,6,7);
newSpline = prevSpline;
newParent = prevSpline.transform;
}

wagon.SwitchTo(newSpline, nearestPointTF, 0);
wagon.transform.parent = newParent;
}
}
}
Reply
#4
Hi all,

Can I use navmesh,A star path finding or other path finding algorithm on curvy2.02? may be curvy2.02 already have a best solution for the navigation algorithm.Thanks
Reply
#5
1.) Yeah, see the GUI example scene. The buttons and the label are using the Animate feature, i.e. they move a delta, then move back. But the same Animation feature can be used to move a certain distance and then stop, including slowdowns and other tweanings.

2.) Triggers are one way, another one would be to utilize controller events such as OnEndCPReached/OnCPReached. Then you get a callback each time the controller moves over a CP and you can switch splines there. Use connections to easily access the next/previous spline in question. For some examples, see CurvyDefaultEventHandler.cs.
Reply
#6
1) But from code it is possible? Smile
Reply
#7
You can use the SplineController from code like any other GameObject. All inspector options and commands (stop/start/play/reset etc.) are available by code as well.
Reply
#8
I tried this Animate feature but with more complex AI or a couple move patterns it is a bit messy and hard to control or tweek. There is maybe different way to move something by specific distance from code?
Reply
#9
Yeah, make a custom controller and use Spline API to move the object the way you like, e.g. CurvySpline.MoveByDistanceFast().
Reply
#10
Thanks for all your help Wink You are the best!

I don't understand this method very well, but I created simple custom controller:

Code:
public class EnemyWagonController : SplineController
{
private float _tfValue;
private int _direction = 1;

void Awake()
{
Vector3 nearestPoint;
_tfValue = Spline.GetNearestPointTF (transform.localPosition, out nearestPoint);
transform.localPosition = nearestPoint;
}

public override void Refresh ()
{
Move ();
}

void Move()
{
Vector3 nearestPoint;
_tfValue = Spline.GetNearestPointTF (transform.localPosition, out nearestPoint);
transform.localPosition = Spline.MoveByLengthFast (ref _tfValue, ref _direction, 2f, CurvyClamping.PingPong);
}
}

And I assume MoveByLengthFast(ref float tf, ref int direction, float distance, CurvyClamping clamping) distance is speed, but how can I track my controller reached target distance? Wink

Sorry for my stupid questions.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Information Questions regarding spline colliders and collisions with rigidbodies Spyboticer 7 1,340 01-20-2025, 12:25 PM
Last Post: _Aka_
  Questions before buying erk13 3 609 05-15-2024, 10:38 PM
Last Post: _Aka_
  Scene 51 questions lukasynthetic 3 599 06-22-2022, 04:12 AM
Last Post: _Aka_
  Spline editing questions giollord 5 980 12-04-2021, 02:24 PM
Last Post: _Aka_

Forum Jump: