• News

• Industries

• Learning & Support

• Community

• Marketplace

# Distance along spline

Hello, heads up I’m not a programmer

I’m determining an alpha (float) for distance along a spline based on character height within a trigger capsule to ascertain position of character relative to a spiral staircase for a (CCDIK effector) which works fine… except. The character has IK for the legs that make the “distance along spline” (based on current character height) - jump too dramatically when going up each step. Is there a better method of calculating player world location relative to distance along a spline other than character world z?
Direction vectors are a problem in this specific case as the spline spirals up and around itself as it is a spiral staircase as shown below.
I’ve thought about making more spline points and calculating spline by spline comparing right vectors for example. But I figure there is a much simpler way like intersecting capsules or using a trace to player.

https://forums.unrealengine.com/filedata/fetch?type=thumb

The concept if you haven’t guessed already is to simply slide the hand along the railing as players go up and down - the up and down stairs and switching arms is taken care of with forward vector compared to “current” effector spline right vector (which is after the fact the alpha has been calculated). I’ve also smoothed out the alpha calculation by turning off IK and making a ramp - which is not ideal ofc. Any help appreciated - I think there is a simple math solution there somewhere.

http://blueprintue.com/render/7z8epbiq Actor Blueprint (staircase)
https://blueprintue.com/render/6p_ygcy7 Player AnimGraph

Bumping because editing my post put me on page 956…

wow. Ok. Why all of this?

The hand is attached to the character. you always know where the hand is.
As such, there is no need to keep track of the Z or position on the staircase at all - because the hand is always near the character already.

Trace from the hand bone to the rail, see if it’s within the correct range, and attach the hand to the rail by moving the IK bone position like for the feet.

Also, again, the hand is always there, you could probably fake the whole thing by just moving the hand in a custom “climb stairs” upper body slot montage.

You can tie the whole thing to the right foot plant curve for your Alpha on the IK if you end up using the IK. when the foot plants is usually when the hand grabs the rail

Thanks for the response but I’m not sure you’ve understood what I’m trying to do here, the alpha determines distance along spline and calculating that to use the position and rotation for the hand at any given point. Using the hand arrow z doesn’t matter if it’s any part of the body or player capsule - they all move as one and I need player world space.

I’m already using capsules to trigger the event and the CCDIK is already attached to the rail (based of the alpha),

The slot is a good idea to steady the hand as it carries some of the walk and run animation, but I think you are thinking of grabbing the rail on each step when I just want the hand to slide up and down the railing. The blueprint works fine except that the alpha driving the point along the spline is jumpy as is the IK of the feet that create the alpha - a smooth ramp instead of steps works as I want it at the expense of not having IK on the steps (I want both).

I think you may have an issue with your IK setup. Nothing should be jumping UP. If anything it should be dragged downwards and the capsule should shrink to stay inline with the head.
so it wouldn’t jump, it would go back to where it is supposed to be - whenever the foot is off the ground as driven by an animation curve in the walk cycle.
at least that’s hoe normal foot IK should work.

all that said, what I said still stands.
The rail is a constant and unless you are literally jumping when climbing the stairs it should always be next to the hand regardless of how much up and down the animation goes (because the rail goes up consistently as well).

but let’s assume your animation is foobar and your hand goes up and down around/into the rail.

In this case you would create a line trace from the handbone, 100 units above it so you can get both instances of where the handrail is - above or below - and you would simply place your IK bone on that modified distance.
current hand + modified (- or +) value.

Instead of moving the bone in world space which can be prone to a lot more errors, you’d be doing the math in local space.

does that make sense?

Bonus points, you can invert the normal of the hit and get an approximate angle that you do need to adjust to tilt the hand if the rail is ever aligned differently.
to do that I would make the simple collision UCX mesh of the rail square so as to avoid the hit result returning anything but the proper incline of the normal. If your Collision is round then you won’t really be able to get accurate angles (or placement if your animation shifts side to side).

Yeah, I’ve tired and failed to make an IK feet system in the past and that’s why I’m using ALS (Advanced Locomotion System) for this project, the whole player capsule moves based on the root which the feet determine as the player moves up and down terrain - it’s not a smooth transition unfortunately.

Well that’s it though, the hand, body and all jump as the foot IK moves the legs up to the new pelvis position in a jagged way. This is why I was thinking of a Feet IK offset to the Hand effector a while ago. But perhaps you’re right that fundamentally I went in a wrong direction of blueprinting this - I was so **** close too

I’ll try a trace as you’ve suggested and do away with the spline completely (the rail was made externally to UE4). Perhaps I’ll upload a video of what I got so far.