Jump to content

Unity animation duplication

Go to solution Solved by Guest,
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.

Spoiler

 


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.

Hi! So I mostly understand animations in unity now, thanks to your recommendation in my other thread about iheartgamedev but I still have a problem and after extensive googling and not finding it in iheartgamedev's content and also not getting an answer in his discord, I have to ask here because I tried a lot of stuff and just have no idea how to proceed. If you know great! If you don't know it's still fine, thanks to your recommendations I already learned a lot about unity and I am sure I will find someone with enough skill in unity to know. But then again if anyone here knows please how do I solve this:

 

 

So I have created animations that are activated by scripts for each object. The problem is that when I mouse click I activate the animation for all objects(since that is how I want it to be).I want to mouseclick on an object to activate the animation. But even though I assign the scripts to different objects, I cannot tell Unity in a script that this action is confined to the borders of the object. So now wherever I mouse click, all the animations play. So if you know a solution, I will appreciate it.

 

 

 

 

 

Link to comment
https://linustechtips.com/topic/1471589-unity-animation-duplication/
Share on other sites

Link to post
Share on other sites

I won't give you the answer, but I will give you some clues:

1. How do you stop the animations from playing so the ones not being clicked don't get activated?
2. How do you know you clicked on one? What are some tools you can use to figure out what you clicked on?
3. How do you tell the one you clicked on to activate?

Think outloud and we'll guide you the way.

Link to post
Share on other sites

2 hours ago, fpo said:

I won't give you the answer, but I will give you some clues:

1. How do you stop the animations from playing so the ones not being clicked don't get activated?
2. How do you know you clicked on one? What are some tools you can use to figure out what you clicked on?
3. How do you tell the one you clicked on to activate?

Think outloud and we'll guide you the way.

well the first one I am not really sure. I guess that's kind of my question. so

1. not sure, but I think using conditions(bools)

2.I don't really know about tools, maybe the name of the animation clip or the animator controller

3.Using a bool and if statements, I set the bool to true and that's the condition for the transition to activate and play the animation.

 

By the way I am using an idle state for each animation and from that I have a transition with a bool as a trigger which activates the actual animation(transition from idle state to the animation) that's something I glossed over and I think it might be important.

Link to post
Share on other sites

7 hours ago, stefanmz said:

well the first one I am not really sure. I guess that's kind of my question. so

1. not sure, but I think using conditions(bools)

2.I don't really know about tools, maybe the name of the animation clip or the animator controller

3.Using a bool and if statements, I set the bool to true and that's the condition for the transition to activate and play the animation.

 

By the way I am using an idle state for each animation and from that I have a transition with a bool as a trigger which activates the actual animation(transition from idle state to the animation) that's something I glossed over and I think it might be important.

1. A boolean can work. 

2. I'm assuming your game is 3D. How do you tell if someone is pointed at something in 3d space? You might have to look it up. 

3. That can work. 

 

Idle state is fine. You should use idle states. 

Link to post
Share on other sites

5 hours ago, fpo said:

1. A boolean can work. 

2. I'm assuming your game is 3D. How do you tell if someone is pointed at something in 3d space? You might have to look it up. 

3. That can work. 

 

Idle state is fine. You should use idle states. 

ok so about 2, are you referring to coordinates? Should I like include mouse-coordinates for each object in C#? If so, how do I do this in C# I don't exactly remember. I could look it up or if you want you might tell me. Or is it not coordinates? Also if it is coordinates, that's a good but not perfect solution. It's fine, it will work, but ideally I want the action tied to the object in unity, like wherever the object is, it knows when I click on it. Is that not possible? Even if it's not with a C# script, but like in the inspector window of the editor or something. There is event triggers but that doesn't work this way. So I don't know what do you say about that?

Link to post
Share on other sites

Just now, stefanmz said:

ok so about 2, are you referring to coordinates? Should I like include like mouse-coordinates for each object in C#?

Are you making a 2d game or 3d game? 

Just now, stefanmz said:

 I want the action tied to the object in unity, like wherever the object is, it knows when I click on it.

Excellent! You are heading in the right direction. 

Just now, stefanmz said:

So I don't know what will you tell me?

If it's a 3d game, what would be a good way to tell if something is in the path of something?

 

If it's a 2d game, how do you tell where something is in 3d space? 

Link to post
Share on other sites

8 minutes ago, fpo said:

Are you making a 2d game or 3d game? 

Excellent! You are heading in the right direction. 

If it's a 3d game, what would be a good way to tell if something is in the path of something?

 

If it's a 2d game, how do you tell where something is in 3d space? 

It's a 3d game, but 3d also has coordinates-x,y,z you can also tell where an object is in 3d space you just need 3 coordinates instead of 2. Is it something else? If it's something else , you have to tell me so at least I know it's not coordinates and I look it up. When you tell me something is in the path of something I think of trajectory, or Collision physics or whatever in unity( when you make collision) but I don't know if that's the answer.

 

Edit: I found something called pathfinding in unity. Is it that?

Link to post
Share on other sites

5 minutes ago, stefanmz said:

I don't know if that's the answer.

We're going to find it. 

I'm helping you think through how to solve this problem so you can think on how to solve problems in the future. 

 

5 minutes ago, stefanmz said:

It's a 3d game, but 3d also has coordinates-x,y,z

Awesome. So we know we *can* use coordinates. 

It would be complex though. 

5 minutes ago, stefanmz said:

When you tell me something is in the path of something I think of trajectory, or Collision physics or whatever in unity( when you make collision) but I don't know if that's the answer.

So there's two paths here. 

 

You think of collision and that is both answers. 

 

What are two ways you can detect some kind of collision in unity? 

One is obvious. The other is abstract. 

Link to post
Share on other sites

1 minute ago, fpo said:

We're going to find it. 

I'm helping you think through how to solve this problem so you can think on how to solve problems in the future. 

 

Awesome. So we know we *can* use coordinates. 

It would be complex though. 

So there's two paths here. 

 

You think of collision and that is both answers. 

 

What are two ways you can detect some kind of collision in unity? 

One is obvious. The other is abstract. 

I honestly have never ever before used unity, not even touched it, so no idea about how to make collision I've just heard like collusion boxes and other stuff but I don't have any structured information. So if it is collision I can look up how to make collision in unity, but I don't know are you sure that seems different from what I want. I want to click on an object and unity knows on what object I clicked. Isn't collision when two game objects interact? Does the mouse pinter count as such object? What about pathfinding?

Link to post
Share on other sites

Just now, stefanmz said:

I honestly have never ever before used unity,

No worries! 

Just now, stefanmz said:

not even touched it, so no idea about how to make collision I've just heard like collusion boxes

What can you tell me about collisions in unity?

Can you find any documentation on collision boxes? 

There are a few types but they're mostly the same. 

IE sphere, cube, capsule, those are the same just different shapes. 

Just now, stefanmz said:

I want to click on an object and unity knows on what object I clicked. Isn't collision when two game objects interact? Does the mouse pinter count as such object?

We can do this. We're making our way. 

 

The mouse isn't in the game world. It is positioned somewhere in the camera. 

Can you get the position of the mouse in the camera? 

Show me some documentation. 

Just now, stefanmz said:

What about pathfinding?

Pathfinding is another subject. 

I cannot think of a way we can use it to do what you want to accomplish by using the mouse to select. 

 

All pathfinding is is the ability to

1. Determine if a path can be made from one point to another. 

2. The shortest path to the destination from the starting point or the first path found. 

Link to post
Share on other sites

9 hours ago, fpo said:

No worries! 

What can you tell me about collisions in unity?

Can you find any documentation on collision boxes? 

There are a few types but they're mostly the same. 

IE sphere, cube, capsule, those are the same just different shapes. 

We can do this. We're making our way. 

 

The mouse isn't in the game world. It is positioned somewhere in the camera. 

Can you get the position of the mouse in the camera? 

Show me some documentation. 

Pathfinding is another subject. 

I cannot think of a way we can use it to do what you want to accomplish by using the mouse to select. 

 

All pathfinding is is the ability to

1. Determine if a path can be made from one point to another. 

2. The shortest path to the destination from the starting point or the first path found. 

yeah so I looked at both locating the mouse in the world and collision and honestly both seem very complicated and far from my idea. I mean it's a simple game and I don't need to learn complicated stuff just because it's gonna be useful for other unity projects if I can do a simple fix. Like even if that's the way to do it, it's still complicated for like what idea I had. So is there some quick way that I can do this? Like finding some thing in the inspector window for 5 minutes? Anything simpler? Or should I just basically use the coordinates of the mouse instead of using the actual object?

Link to post
Share on other sites

8 hours ago, stefanmz said:

yeah so I looked at both locating the mouse in the world and collision and honestly both seem very complicated and far from my idea. I mean it's a simple game and I don't need to learn complicated stuff just because it's gonna be useful for other unity projects if I can do a simple fix. Like even if that's the way to do it, it's still complicated for like what idea I had. So is there some quick way that I can do this? Like finding some thing in the inspector window for 5 minutes? Anything simpler? Or should I just basically use the coordinates of the mouse instead of using the actual object?

Did you find any documentation at all? 

Link to post
Share on other sites

1 hour ago, fpo said:

Did you find any documentation at all? 

I found this https://docs.unity3d.com/Manual/CollidersOverview.html

collision seems like something different not what I want, are you sure for what I want it's collision? 

I don't know that seems completely different and I found this on mouse position https://docs.unity3d.com/ScriptReference/Input-mousePosition.html and I watched a couple of videos. Seems complicated but more on what I need to do but it's also, you know not connected to the object just to position of the mouse, so this is like coordinates. Which means that even if I do it this way I won't be able to use the object rather than the current coordinates of the object. I don't know this doesn't seem very useful. However if you do not have anything else, I might just use mouse coordinates or look elsewhere for answers.

Link to post
Share on other sites

50 minutes ago, stefanmz said:

Excellent!

50 minutes ago, stefanmz said:

collision seems like something different not what I want, are you sure for what I want it's collision? 

Let's think about this. 

How can you use collision to see if the object you want to select is somewhere? 

 

Think of call of duty. The answer is not difficult to come to. 

50 minutes ago, stefanmz said:

I don't know that seems completely different and I found this on mouse position https://docs.unity3d.com/ScriptReference/Input-mousePosition.html and I watched a couple of videos.

Excellent! 

Keep this mouse position handy. 

Useful to have the mouse position when clicking things on the screen with the mouse. 

50 minutes ago, stefanmz said:

Seems complicated but more on what I need to do but it's also, you know not connected to the object just to position of the mouse, so this is like coordinates. Which means that even if I do it this way I won't be able to use the object rather than the current coordinates of the object. I don't know this doesn't seem very useful.

We will get there. 

50 minutes ago, stefanmz said:

However if you do not have anything else, I might just use mouse coordinates or look elsewhere for answers.

If you're not ready to problem solve then you can find the answer. 

But many developers get trapped in "tutorial hell" where they cannot think for themselves unless someone tells them explicitly what to do. 

 

We're almost there!! Don't give up now. 

Link to post
Share on other sites

On 12/4/2022 at 4:02 PM, fpo said:

Excellent!

Let's think about this. 

How can you use collision to see if the object you want to select is somewhere? 

 

Think of call of duty. The answer is not difficult to come to. 

I have no idea. I haven't played any call of duty, well just a little bit but like really a little bit. I will google it, try to find something. In the meantime, can you give me some more hints?

 

Update: I found collision detection but I don't know if that's the thing.

Link to post
Share on other sites

8 minutes ago, stefanmz said:

I have no idea. I haven't played any call of duty, well just a little bit but like really a little bit. I will google it, try to find something. In the meantime, can you give me some more hints?

 

Update: I found collision detection but I don't know if that's the thing.

What do you do in call of duty?

 

First 5 seconds on Google tell me what you do in the game. 

Link to post
Share on other sites

On 12/4/2022 at 11:02 PM, fpo said:

 

many developers get trapped in "tutorial hell" where they cannot think for themselves unless someone tells them explicitly what to do. 

 

I completely agree with this. I've been there, and its really hard to get out of it. best thing to do is understand the subject, not the project.

 

On 12/4/2022 at 11:02 PM, fpo said:

We're almost there!! Don't give up now. 

Don't give up! 

RELOAD BEFOR QUOTING. I EDIT MY POST ALOT!

MARK MY POST AS THE ANSWER IF I HELPED.

 

CPU: AMD Ryzen 5 5600 | GPU: RTX 2070 Super | Mobo: MSI X470 Gaming Pro | RAM: Corsair vengeance 32GB 8x2 3200mhz CL16 | SSD: Samsung QVO 870 1TB | PSU: SeaSonic FOCUS Plus 750 Gold 750 W 80+ Gold | Cooler: Thermaltake Contac Silent

12 | OS: Windows 11 Pro | Pcpartpicker: https://pcpartpicker.com/list/rGR6gb
Displays: ViewSonic XG2401 23.6" 1920 x 1080 144 Hz 

Laptop: Lenovo Ideapad Gaming i5-1130 RTX3050 16GB | OS: Windows 11 Pro

Link to post
Share on other sites

3 minutes ago, HelloPeople said:

I completely agree with this. I've been there, and its really hard to get out of it. best thing to do is understand the subject, not the project.

 

Don't give up! 

Thank you for reinforcing it. 

 

I was lucky to not get stuck in tutorial hell, but I did lack certain guidance tutorials offer. Tutorials have their place but it's hard to teach how to think. 

Link to post
Share on other sites

23 hours ago, fpo said:

What do you do in call of duty?

 

First 5 seconds on Google tell me what you do in the game. 

um well you shoot guns, I mean I have played a bit. Are you referring to something with like laser pointing to locate where an object is?

Link to post
Share on other sites

6 minutes ago, stefanmz said:

um well you shoot guns, I mean I have played a bit. Are you referring to something with like laser pointing to locate where an object is?

You can do that. 

 

Is there a mathematical concept by chance that would be like shooting a laser? 

 

There's a lot of math in games but if you use an engine like unity, it's likely that they make it easy and will potentially name a tool after a mathematical concept. 

Link to post
Share on other sites

18 hours ago, fpo said:

You can do that. 

 

Is there a mathematical concept by chance that would be like shooting a laser? 

 

There's a lot of math in games but if you use an engine like unity, it's likely that they make it easy and will potentially name a tool after a mathematical concept. 

yeah I don't like math and don't know a lot, so I would probably not be able to name that

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×