Collision with movement along Spline
I'm currently trying to develop a game prototype using Blueprints. The game is a 2.5D Sidescroller where I've set the character up to move along a fixed path using a Spline. So far, movement has been working quite well, up until I starting setting up obstacles (plain boxes) with collision.
The setup I have is very similar to what you find in this thread.
The issue I'm having is that as the character runs into an object, the variable that keeps track of the total distance traveled across the spline ('Spline Distance') keeps increasing. So while the character haven't appeared to move (it's simply been running into the obstacble), it's location along the Spline has changed. If the character then were to jump up above the obstacle, once more enabling them to move forward, they'd "teleport" to the correct distance along spline.
I've tried solving this several ways; moving the character back 1 cm everytime they collide with an obstacle, setting 'Spline Distance' to itself to place the character at a point where it didn't collide with the obstacle, not doing anything if collision is detected, and some other things. Nothing have worked. Either the character gets stuck "inside" the obstacle, or I get a weird case where the character tries to force itself to the new location by sliding along the side of the obstacle until it reaches around the corner and teleports to the "correct" location, and sometimes I get both depending on direction.
Here's a snapshots of the Blueprints handling character movement:
Thanks in advance.
asked Mar 10 '16 at 02:01 PM in Blueprint Scripting
Alright, came up with a functioning solution myself.
I declare an additional float variable called "NewSplineDistance". Somewhere at the start of the blueprint I set NewSplineDistance to be SplineDistance + Velocity (basically). NewSplineDistance is then used calculate the new location of the actor along the spline, which is checked for collision by enabling Sweep (see SetWorldLocationAndRotation). If movement was successful, set SplineDistance to NewSplineDistance. If the character collided, and movement failed, reset the character's location using SplineDistance.
answered Mar 10 '16 at 10:16 PM
This solution work only if you want to stop everytime hit an obstacle, but if you hit a stair that you want climb it? I'll explain ... for example, imagine you are moving your character along spline and encounter a stair mesh that you want to climb on the stair side and block if you are on the "wall side". I make a draw to explain the problem better:
i don't think your solution work. Do you have any idea for solve this problem?
answered May 04 '17 at 09:18 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here