Now to add a sword mechanic. I decided to use a limited raycast instead of an animation and a collider. First of all, I made a boolean called "Attack" and started it as "false". When it changes from false to true, it will trigger things like sound effects.
I then made a public float variable that will define the distance the raycast will go.
Then I made a small script that will draw a raycast for every frame that the game is active. This is really just to test how long I want the range. I also assigned a colo(u)r, since raycasts are by default, invisible.
And there's the ray.
I decided to change the distance to 3, which seems to be a decent range for a sword. No, it is not too long. You have to have some advantage in a game where you're blind.
I then added and if statement that would detect if it hit something, and then output "hit something" in the debug console.
Now it detects when the raycast hits something...or stabs a house.
Next class I will be adding script to make the raycast interact with other objects.
No comments:
Post a Comment