Hello sir. Many thanks for that awesome video. Beginner question here: I try to apply the script to a basic 3D cube to watch it fly around another cube defined as the flying target. I've commented out every part of the code related to animation since I only want the object to move around. For some reason, the cube only rotate on itself but won’t move (transform position doesn't change on any axis). Would you kindly give me some hints ? Thanks.
Thanks for such a well-worded comment :) The part in the script that handles the movement is given below. Maybe add some "Debug.Log" statements there to show you what the values of all the variables are at that point. Also check where speed is allocated a bit earlier (speed = ...) The animation parameters plays a part in these, so it may be that "timeSinceAnim" and "switchSeconds" aren't updated properly after you took out the animation stuff? So, below prevSpeed, speed and timseSinceAnim should not be 0, and direction should not be (0,0,0) if (returnToBase && distanceFromBase < idleSpeed) { body.velocity = Mathf.Min(idleSpeed, distanceFromBase) * direction; } else { body.velocity = Mathf.Lerp(prevSpeed, speed, Mathf.Clamp(timeSinceAnim / switchSeconds, 0f, 1f)) * direction; }
If you need something to fly in a random but controllable way automatically, this script should give you some ideas to apply. Script available at: github.com/ReCogMission/FirstTutorials
I'm a bit late to the party but I'm having a bit of a problem and I think it's probably a quick fix if I knew what I was doing. Basically, the script works great, but I think my animation is messed up. The flying object is "stuck" on the x axis, so it just flies up and down the z axis. Are there any examples out there of good animations I could use to get this finalized? Thanks for sharing such great work... I really appreciate it!
Hi! I haven’t worked with this for a while, but as I remember the animation itself is actually not supposed to influence the movement/position at all. You could apply this to a brick and it should follow the flying path, as long as the code references the correct animation parameter names. Do you not get any error messages? If you like you could search for ‘re cog mission’ on Facebook and messenger me some screenshots/video of what happens and I’ll try to help you out.
@@RecOgMission Thanks for that offer! I'm a Neanderthal and don't even have a Facebook account, but my wife does, so when she gets home tonight I'll have her log in and I'll send you over what I'm seeing. I did some more testing by putting the script on a different object and saw the same behavior, although the x coordinate at which it can't get past changed. So, for example, for the first object it's like there's a glass wall at x = 10, and it just flies up and down that line. For the second object, that invisible wall is at x= 35. It doesn't matter what the original x coordinate of the object is, it flies straight to that "glass wall" x coordinate and stays there. I'm going to start a new project and see if I can get it working in a clean solution. There might be something I've got in my project that's messing with things. Talk to you soon!
As a details oriented, I didnt understand a lot of things, but I followed the tutorial and its working, but I still want to understand what's happening code wise =p Appreciate the effort tho, keep it improving
I remember when I first watched The Usual Suspects. I'd just arrived somewhere with no idea that I was even going to watch a movie, let alone what it would be. So, I had no knowledge or expectation about "something's up in this movie", and it was the perfect prelude to such a brilliantly constructed piece of art.
@@RecOgMission Yeah it's a great movie, used to binge on it along with Man bites dog, Henry portrait of a serial killer, and Hardware among others with my mates back in the day.. Ugh feel old now. Still keep up with the videos. Makes me feel like you CAN teach an old dog new tricks, although they sometimes take longer to learn :D
Hi. This was a long time ago :) I don't think I even have the project anymore - I was practicing stuff. I am using bits of this scene in my current work (weather, flying script, etc.) but the scene as a whole is not really accessible anymore. I can tell you that the horse was a bought asset with animation included (I just added footstep events), the cart was a free asset that I "deconstructed" to allow me to have the wheels and axis as a separate object, so it can rotate, and I hitched it to the horse using Unity's joints system. Physics handled the turning of the wheels due to the friction with the terrain. The trees and terrain were standard Unity assets at the time. I scrounged around for all kinds of free assets, including the cabin and stuff in and around it. I wrote the tree-grow-and-fall script, and am using it's descendent in the game I'm making. Finally, I wrote a basic camera-waypoints system to let the camera fly through the scene. I hope this helps a little bit?
Hello, thank you so much for this video! I have just one issue. Whenever I created my terrain, I set the height to 100. Therefore, when I have attached the home and flying target, the bird is flying under the map. Is there a way to fix this? If so can you please tell me what I can do
It’s been a while since I worked with this... if your home and target game objects are within the 3D space that you want the bird to fly, it should work fine. Maybe check - I recall there being limits to the y-coordinate, which maybe be what forces id lower??
If you just remove the part that adjusts the animator it will work fine. Your model will just be fixed, only turning in terms of look direction and tilting a bit around turns.
@@RecOgMission oh nice thanks! i am quite new at unity so i deleted some lines but there are errors saying: arugument exception:JSON parse error:missing a name for object memeber. I think it is because i didnt delete all of the animation codes? Which are the exact lines of them...(Sorry about my silly question, i am a completely newbie at this)
@@murrayzhu3959 I can't tell you why those errors are there. It could be anything. You need some basic coding skills to adapt scripts. Delete what you think you should delete one at a time and check when the error occurs. Then, either you need to delete the part that gives the error too, or you should not have deleted the thing you did.
Very interesting! I am trying to adapt this to bees in a fairly confined area. They fly from flowers to flowers then head home. There is no animation to speak of and following your advice for the basic 3D cube, my pollinator has some twitchy movements but does not actually fly around. I'll continue to experiment with commenting out the animation requirements but I am more of a dreamer than a coder! Keep up the great work.
@@RecOgMission Funny enough, this thought did occur to me as well. I am just a such a fan of randomness and I like being surprised by what happens on the screen. But maybe you are right as this area is pretty confined. Maybe I can figure out how I can get it to travel randomly along the curve. Thanks for the reply! I still have use cases for random movements though, as I well also try and adapt this to autonomous ground agents that sweep up the floor. Think Wall-E cleaner robots. Thinking about it, they originally follow a defined path but then one breaks free and starts following his own path. So maybe I'll set up various paths using curves and randomly switch between them. Your reply has got me thinking. Thanks again!
I also love watching ‘agents’ acting out programmed algorithms, especially with some randomness added ;) Good luck, and let me know if you need any help, either conceptually or in terms of code. Come to think of it, I’ve actually made a script where I can give my camera a set of waypoints, with a viewing direction for each point, as well as required speed for that point, and it then creates a bezier curve path through these points, lerping between look directions and required speed. This could be exactly what you need, since you can add random points based on some algorithm, and still have the smoothness of the bezier functions and lerping.
@@fitzrandolph I actually use it to create cinematic scenes for trailers and other material (and in-game too), so it's exactly like a replay-camera, just "live".
Hi. What's the error? Here's the Unity documentation. It's supposed to be a straightforward method. Are your inputs correct? Have you included an axis around which the "from" and "to" vectors needs to be rotated? docs.unity3d.com/ScriptReference/Vector3.SignedAngle.html
Presently working on my final project for a BS in game design. We want to make some sort of aerial enemy AI for the player to shoot at. I am also working on a personal project that will involve aerial and space combat so I won't be able to rely on navmesh.
Hi Samantha. I suppose you'd probably want to change the "taking off" and "landing" speed/momentum buildup and slow-down, and your "waypoints" would be less random, but you could definitely adapt it for planes
Hi, thanks a lot for this helpful tutorial! I'm trying to add collision detection to this script but I couldn't come up with a working solution. Could you please point me to the direction of how to do it?
Hi. You’d want to work with the distances between units, and the angles telling you which direction to turn to. I’ve not done anything like that on this script, but maybe watch this video, where I implement collision detection for units: ua-cam.com/video/SbTiznMhbBQ/v-deo.html
@@RecOgMission Thanks a lot, i just realized I wrote " collision detection" and I meant "collision avoidance" but I think to get it. Anyway your video is interesting and I'll give it a try but I am looking for a simpler solution in which each unit can avoid an environment, not necessarily each other.
You can calculate the distances between and angles from the bird’s position to the thing to avoid (or to it’s edges if a large area), then the closer the bird gets to ‘colliding’, the more you force the next position to somewhere behind the bird. You can ‘lerp’ between something like 90 degrees and 180 degrees depending on proximity, meaning the ‘swerve’ will be more pronounced the closer to colliding.
Hi Luben - I'm glad you like the videos ;) 2nd Pack (with the bird I used): assetstore.unity.com/packages/3d/characters/animals/animal-pack-deluxe-v2-144071 1st Pack: assetstore.unity.com/packages/3d/characters/animals/animal-pack-deluxe-99702
@@RecOgMission Thank you very much man! I will be so happy if u continue to make this kind of tutorials.I really love the vegetation/nature interaction in games.It feels so alive. I am making exploration nature game and this is so useful! Thanks u again !
I am currently busy optimizing many things in my game. One big reason for wanting to do this is so that I can add more visual "interactions", like flying birds, flowers, etc. The more resources I can save in the bare necessities, the more resources you have for bells and whistles, greatly adding to the enjoyment and "fullness" of the game.
@@RecOgMission Hey man, i tested it and it works great! I have only 1 simple question.Is have event manager system, and i want it to link the bird and script with the event system (for example, if it goes night birds return to base) but i cannot find the function when i link the script.Is it possible that function to be added and called when it needed? :) Thanks in advance!
If you have a system that trigger actual Unity events, you could add a ‘return home’ method for the bird and subscribe to the specific event (for example ‘getting dark’). Then whenever that event triggers/fires, the bird’s subscribed event will fire.
Hello sir. Many thanks for that awesome video.
Beginner question here: I try to apply the script to a basic 3D cube to watch it fly around another cube defined as the flying target. I've commented out every part of the code related to animation since I only want the object to move around. For some reason, the cube only rotate on itself but won’t move (transform position doesn't change on any axis). Would you kindly give me some hints ? Thanks.
Thanks for such a well-worded comment :)
The part in the script that handles the movement is given below. Maybe add some "Debug.Log" statements there to show you what the values of all the variables are at that point. Also check where speed is allocated a bit earlier (speed = ...) The animation parameters plays a part in these, so it may be that "timeSinceAnim" and "switchSeconds" aren't updated properly after you took out the animation stuff? So, below prevSpeed, speed and timseSinceAnim should not be 0, and direction should not be (0,0,0)
if (returnToBase && distanceFromBase < idleSpeed)
{
body.velocity = Mathf.Min(idleSpeed, distanceFromBase) * direction;
}
else
{
body.velocity = Mathf.Lerp(prevSpeed, speed, Mathf.Clamp(timeSinceAnim / switchSeconds, 0f, 1f)) * direction;
}
@@RecOgMission That was really helpful. Thank again for you dedication.
If you need something to fly in a random but controllable way automatically, this script should give you some ideas to apply.
Script available at: github.com/ReCogMission/FirstTutorials
Thank you
My pleasure!
I'm a bit late to the party but I'm having a bit of a problem and I think it's probably a quick fix if I knew what I was doing. Basically, the script works great, but I think my animation is messed up. The flying object is "stuck" on the x axis, so it just flies up and down the z axis. Are there any examples out there of good animations I could use to get this finalized? Thanks for sharing such great work... I really appreciate it!
Hi! I haven’t worked with this for a while, but as I remember the animation itself is actually not supposed to influence the movement/position at all. You could apply this to a brick and it should follow the flying path, as long as the code references the correct animation parameter names. Do you not get any error messages? If you like you could search for ‘re cog mission’ on Facebook and messenger me some screenshots/video of what happens and I’ll try to help you out.
@@RecOgMission Thanks for that offer! I'm a Neanderthal and don't even have a Facebook account, but my wife does, so when she gets home tonight I'll have her log in and I'll send you over what I'm seeing. I did some more testing by putting the script on a different object and saw the same behavior, although the x coordinate at which it can't get past changed. So, for example, for the first object it's like there's a glass wall at x = 10, and it just flies up and down that line. For the second object, that invisible wall is at x= 35. It doesn't matter what the original x coordinate of the object is, it flies straight to that "glass wall" x coordinate and stays there. I'm going to start a new project and see if I can get it working in a clean solution. There might be something I've got in my project that's messing with things. Talk to you soon!
Huge game changer, thank you, I changed your code around a little bit to allow for precise landingPoints.
I'm glad it was helpful!
Thank you this is was a good tutorial for me to base my fish ai off of
As a details oriented, I didnt understand a lot of things, but I followed the tutorial and its working, but I still want to understand what's happening code wise =p
Appreciate the effort tho, keep it improving
Thank you!
Hello, can you please give the script link in github?
Hi. Please try this link. Please let me know if it works:
github.com/ReCogMission/FirstTutorials
Another Great tutorial, from the Usual suspect, Thanks Keyser Söze ;)
I remember when I first watched The Usual Suspects. I'd just arrived somewhere with no idea that I was even going to watch a movie, let alone what it would be. So, I had no knowledge or expectation about "something's up in this movie", and it was the perfect prelude to such a brilliantly constructed piece of art.
@@RecOgMission Yeah it's a great movie, used to binge on it along with Man bites dog, Henry portrait of a serial killer, and Hardware among others with my mates back in the day.. Ugh feel old now. Still keep up with the videos. Makes me feel like you CAN teach an old dog new tricks, although they sometimes take longer to learn :D
Can you also make tutorial how to make that scene.
With house and horse and npc walking..
I always dreaming to make a small village simulations
Hi. This was a long time ago :) I don't think I even have the project anymore - I was practicing stuff. I am using bits of this scene in my current work (weather, flying script, etc.) but the scene as a whole is not really accessible anymore. I can tell you that the horse was a bought asset with animation included (I just added footstep events), the cart was a free asset that I "deconstructed" to allow me to have the wheels and axis as a separate object, so it can rotate, and I hitched it to the horse using Unity's joints system. Physics handled the turning of the wheels due to the friction with the terrain. The trees and terrain were standard Unity assets at the time. I scrounged around for all kinds of free assets, including the cabin and stuff in and around it. I wrote the tree-grow-and-fall script, and am using it's descendent in the game I'm making. Finally, I wrote a basic camera-waypoints system to let the camera fly through the scene.
I hope this helps a little bit?
@@RecOgMission
Thanks, help so much
Damn where are u😮
Right here...?
Thats Pretty Awsome Even Its 4 years
Great tutorial!! birds are now flying around in my game :)
Great stuff. It adds so much :)
Hello, thank you so much for this video! I have just one issue. Whenever I created my terrain, I set the height to 100. Therefore, when I have attached the home and flying target, the bird is flying under the map. Is there a way to fix this? If so can you please tell me what I can do
It’s been a while since I worked with this... if your home and target game objects are within the 3D space that you want the bird to fly, it should work fine. Maybe check - I recall there being limits to the y-coordinate, which maybe be what forces id lower??
@@RecOgMission Thank you so much for the fast response! I don't really understand on which window I can do that in.
@@RecOgMission nvm, I fixed it! Thank you again :)
Great!
Hi! Very nice video but i was wondering how can i still make it work if i dont have any animation? Thanks!
If you just remove the part that adjusts the animator it will work fine. Your model will just be fixed, only turning in terms of look direction and tilting a bit around turns.
@@RecOgMission oh nice thanks! i am quite new at unity so i deleted some lines but there are errors saying: arugument exception:JSON parse error:missing a name for object memeber. I think it is because i didnt delete all of the animation codes? Which are the exact lines of them...(Sorry about my silly question, i am a completely newbie at this)
@@murrayzhu3959 I can't tell you why those errors are there. It could be anything. You need some basic coding skills to adapt scripts. Delete what you think you should delete one at a time and check when the error occurs. Then, either you need to delete the part that gives the error too, or you should not have deleted the thing you did.
Thank you very much! You helped me a lot with my student project
My pleasure!
Thank you so much was looking for something just like this!
Glad it could help you out!
Very interesting! I am trying to adapt this to bees in a fairly confined area. They fly from flowers to flowers then head home. There is no animation to speak of and following your advice for the basic 3D cube, my pollinator has some twitchy movements but does not actually fly around. I'll continue to experiment with commenting out the animation requirements but I am more of a dreamer than a coder! Keep up the great work.
Hi. Maybe you could experiment with creating flying paths with bezier curves if you don’t need random changes in flight paths?
@@RecOgMission Funny enough, this thought did occur to me as well. I am just a such a fan of randomness and I like being surprised by what happens on the screen. But maybe you are right as this area is pretty confined. Maybe I can figure out how I can get it to travel randomly along the curve. Thanks for the reply! I still have use cases for random movements though, as I well also try and adapt this to autonomous ground agents that sweep up the floor. Think Wall-E cleaner robots. Thinking about it, they originally follow a defined path but then one breaks free and starts following his own path. So maybe I'll set up various paths using curves and randomly switch between them. Your reply has got me thinking. Thanks again!
I also love watching ‘agents’ acting out programmed algorithms, especially with some randomness added ;) Good luck, and let me know if you need any help, either conceptually or in terms of code. Come to think of it, I’ve actually made a script where I can give my camera a set of waypoints, with a viewing direction for each point, as well as required speed for that point, and it then creates a bezier curve path through these points, lerping between look directions and required speed.
This could be exactly what you need, since you can add random points based on some algorithm, and still have the smoothness of the bezier functions and lerping.
@@RecOgMission Sounds really interesting. It’s almost like you are describing a replay camera. Like something a player might see after the race.
@@fitzrandolph I actually use it to create cinematic scenes for trailers and other material (and in-game too), so it's exactly like a replay-camera, just "live".
Please....the vector3.SignedAngle() used in your code. Is giving me an error in unity5
Hi. What's the error?
Here's the Unity documentation. It's supposed to be a straightforward method. Are your inputs correct? Have you included an axis around which the "from" and "to" vectors needs to be rotated?
docs.unity3d.com/ScriptReference/Vector3.SignedAngle.html
amazing tutorial. thank you so much
:)
This was exactly what I was looking for thanks!
I’m glad you can use it! What are you working on?
@@RecOgMission The company I work for is making a virtual space for teaching computer science with games!
I also added a way to lock the x and z rotation so that this works for fish!
@@kierrasearle8006 Yes, you could leave out the "leaning" and "tilt" to simulate fish movement. ;)
thanks, so great this base script !
So glad you can use it!
great men! excellent tutorial and very helpful
Thanks, I'm glad you could use it! Are you making a game?
@@RecOgMission yeah men, its still alpha... If hoy want check It out: instagram.com/p/CFJM90VhgJL/?igshid=8yardr9wy5qt
This is great. I've been wondering how to implement airborne AI for awhile now and this is definitely a good starting point.
Glad you can use it! What are you making?
Presently working on my final project for a BS in game design. We want to make some sort of aerial enemy AI for the player to shoot at. I am also working on a personal project that will involve aerial and space combat so I won't be able to rely on navmesh.
Good luck - let me know how it goes / share a video!
Hi im making an Airport management sim, would this also work for planes?
Hi Samantha. I suppose you'd probably want to change the "taking off" and "landing" speed/momentum buildup and slow-down, and your "waypoints" would be less random, but you could definitely adapt it for planes
Nice
Thanks
Hi, thanks a lot for this helpful tutorial! I'm trying to add collision detection to this script but I couldn't come up with a working solution. Could you please point me to the direction of how to do it?
Hi. You’d want to work with the distances between units, and the angles telling you which direction to turn to. I’ve not done anything like that on this script, but maybe watch this video, where I implement collision detection for units:
ua-cam.com/video/SbTiznMhbBQ/v-deo.html
@@RecOgMission Thanks a lot, i just realized I wrote " collision detection" and I meant "collision avoidance" but I think to get it. Anyway your video is interesting and I'll give it a try but I am looking for a simpler solution in which each unit can avoid an environment, not necessarily each other.
You can calculate the distances between and angles from the bird’s position to the thing to avoid (or to it’s edges if a large area), then the closer the bird gets to ‘colliding’, the more you force the next position to somewhere behind the bird. You can ‘lerp’ between something like 90 degrees and 180 degrees depending on proximity, meaning the ‘swerve’ will be more pronounced the closer to colliding.
@@RecOgMission I'll try, thanks
Hello and thanks for this amazing series.I cannot find animations in asset store.Could you please give me link? :) Thanks!
Hi Luben - I'm glad you like the videos ;)
2nd Pack (with the bird I used): assetstore.unity.com/packages/3d/characters/animals/animal-pack-deluxe-v2-144071
1st Pack: assetstore.unity.com/packages/3d/characters/animals/animal-pack-deluxe-99702
@@RecOgMission Thank you very much man! I will be so happy if u continue to make this kind of tutorials.I really love the vegetation/nature interaction in games.It feels so alive. I am making exploration nature game and this is so useful! Thanks u again !
I am currently busy optimizing many things in my game. One big reason for wanting to do this is so that I can add more visual "interactions", like flying birds, flowers, etc. The more resources I can save in the bare necessities, the more resources you have for bells and whistles, greatly adding to the enjoyment and "fullness" of the game.
@@RecOgMission Hey man, i tested it and it works great! I have only 1 simple question.Is have event manager system, and i want it to link the bird and script with the event system (for example, if it goes night birds return to base) but i cannot find the function when i link the script.Is it possible that function to be added and called when it needed? :) Thanks in advance!
If you have a system that trigger actual Unity events, you could add a ‘return home’ method for the bird and subscribe to the specific event (for example ‘getting dark’). Then whenever that event triggers/fires, the bird’s subscribed event will fire.