Unity animation duplication
1 hour ago, stefanmz said:So I found a YouTube video from unity explaining it using a box and a parachute but it seems too complicated and I can't really think how my example would fit in that script. So is there some generic script that is used for raycasting? Like a template? So I can use that and learn from it? Can you send me one? I will try to find one but if you can find it pls send it to me.
Here is the official text documentation.
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
I found the video you were talking about. I miss this era of unity tutorials because they were amazing.
In the diagram from 0:25 until he goes to the engine explains the arguments.
Before that he explains in english what is going on.
Origin is a location in 3d space. I assume you know what a position is.
Direction is a bit confusing but it's a vector. (Yes so is position but vectors are often considered more in direction afaik)
So if you did direction like
(0, 0, 1)
This means it will go straight towards the positive Z direction.
So when you move things around, if the position in Z increases, that's the positive Z direction.
I'm hoping you can infer the other 5 directions.
hitInfo is a "structure" called RaycastHit.
This collects what collider was hit, where it was hit, and ...
Here's the complete documentation page on it:
https://docs.unity3d.com/ScriptReference/RaycastHit.html
Layer mask is a complex subject. I won't get into it but basically you can ignore certain things if you want to.
maxDistance is how far it checks.
Picture you paused your game, took a big stick, and put on end at the origin argument & aimed it in the direction argument direction.
The length of the stick is the maxDistance in unity units. (1 unit is supposed to be about 1 meter)
at 2:10 you see the script appear
Physics.Raycast returns true if it hits something. That's all it checks.
The hitInfo has the word "out" before it.
Knowing English ourselves, we can infer that this could be some kind of output...
I know C#, so I am telling you, yes, it is an output. This gives more power to programmers instead of just relying on functions returning things.
So the argument "hit" passed in was defined on line 14 in the video C# script.
Physics.Raycast has assigned the RaycastHit value from the raycast query to the variable named hit.
Finally, deploymentHeight is how far the raycast shoots.
This is executed in the update method, so every single frame of the game, this code executes.
The part that probably confused you is that on line 15, a variable "landingRay" of type Ray is defined. This was done to fill in the first 2 arguments of the Raycast with only 1 argument.
What can you tell me using this information in how it relates to your initial question about being able to click things with your mouse?
1. What do the units need attached to them?
2. Where would the raycast start?
3. When you clicked on a unit, how would you consider getting the unit using the raycast?
4. Bonus question... How would you go about finding the direction argument? You can use Google. The answer to question 2 will help you.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now