Hello, I'm trying to implement the Dash ability to my character, using Bolt and State Graphs. Has anyone ever done it? I'm having trouble with logic. I would like to start the Dash when I press the button, I move to a PreDash state where I control the direction and with the BoxCast I detect the distance to an object. If there are no obstacles, I move 3 units, otherwise I approach the distance detected by the Boxcast. I have a hard time getting the character to move, in the Dash state, using rigidboy.moveposition, because it only moves on the first frame, instead it should stay in the Dash state until my position is equal to the Target position I calculated earlier. Can anyone at least point me in the right way to see this problem? Thank you
Define a variable Dashing (better as a bool), set it to false Define a variable DashTimer (probably a float), set it to zero - when player want to dash, test if dash is possible, if yes, set dashing to true, set - if dashing is true, test exit condition (for example DashTimer= 0, or collision with wall, enemy, or state is hurt, etc ...) -- if there is an exit condition Dashing = false, DashTimer = 0, set relevant state and variable --else DoDashMove() (increment position in direction of dashing, play animation, sound, fx, etc...)
Thank you neoshaman, since my last message, I implemented a working version of Dash (as I wrote earlier, I am using Bolt and State Machine), but I miss to implement exactly what you suggested: - if dashing is true, test exit condition (for example DashTimer= 0, or collision with wall, enemy, or state is hurt, etc ...) so now I will get back to work to complete a timer that can interrupt the movement, also because it protects me from any bugs related to the movement of the character (it's a long story).
ok then I don't have to calculate a target position (in my case, forward 3 units, if there are no other obstacles), but I have to go forward until DashTimer = 0. Correct?
there is many to skin a cat, it depend on the need of the project, you can have both condition to exit anyway. It's just I probably misread and thought it was 3s instead of 3 units. The logic would be similar anyway, compare the distance instead of time "start position - (start position + displacement vector)". Also in both case I would use "0 < value" instead of "=" (really it should be "==" because comparison), precising just in case of, as it was implicit. The reason is that float can be any small number and jump over the zero, therefore never strictly equal to 0. Think of it like that, you want the character to be in a state: 0 - you set the state or check if the state is active 1 - when you enter the state you initialize variable (for example duration or starting point as current position) 2 - you execute the state main code then check exit condition 3 - if exit conditions true, then clean the state and set the next state and its data, ELSE continue execution of current state.
Yes you are right. For the moment I move the character only by calculating the distance between origin and target position. I know that the system I used is very poor. I would like to improve it. and here is where I check the distance between the character and the previously calculated targetposition: the above is not good if the character moves very fast. I need to think of a function that computes more robustly when I pass the target position. For now I have not found any bugs on the system that I have implemented to stop the character, in front of an obstacle.