#simple dash script
1 messages · Page 1 of 1 (latest)
Start with sharing the !code properly(uploading it to one of the paste sites, as it's too big for in line code block).
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
A tool for sharing your source code with the world!
is this right?
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
Mathf.Max is neat tnx