#simple dash script

1 messages · Page 1 of 1 (latest)

patent fulcrum
#

made a simple dash script way too complicated
its the first full feature i wrote on my own without watching tutorial etc
anyway to simplify the script so that its not just buncha if statements

versed kraken
zinc irisBOT
patent fulcrum
#

is this right?

royal wigeon
#

The first basic thing is that you don't need a separate variable to prevent multiple if statements from running, that's what else if is for

#

The way to handle situations like this is that when you have the 4 lines of code that repeat in every if block and only two of them have variations, you take the 4 lines and think of how each line needs to vary. For example in the last line the only difference is that it uses either speedometer.XZspeed or DashSpeed based on the condition speedometer.XZspeed >= DashSpeed or speedometer.XZspeed < DashSpeed so that can be checked separately:

#
float multiplier = Mathf.Max(speedometer.XZspeed, DashSpeed); 
rb.linearVelocity = new Vector3(strafeDirection.x * multiplier, rb.linearVelocity.y, strafeDirection.z * multiplier);
#

Calculating the strafeDirection vector can probably also be done smarter but that would depend on if there's some other info that could be used like the player model's orientation