It's almost a crime that this video only has 1.8k views. Perfectly explained, very well done and completely solved my problem. thank you very much. Liked and subscribed.
Amazing and informational. Really easy to follow. Thank you for a great tutorial! Had some issues, but I solved them by looking through most comments here: I managed to solve the issue with the object flying towards the camera when pressing the key, by changing the layer of the object prefab to "Ignore Raycast". If you need it on Default, you can set it to be on default layer right before making the current selected object null. This way, you cannot place other objects on this object. However, I suggest doing some proximity calculations to not be able to place an object near certain colliders (other buildings, props). Another issue was my object sinking halfway into my terrain. I changed its pivot point to be right on the bottom of the object in Blender.
Thanks. I thought the shuddering effect was that the origin problem, and you can fix the origin problem in Unity by making the prefab a parent of an empty and setting the origin of the empty to 0. Saves a trip into Blender. Cheers!
yeah I agree with previous comment, this is one of the best placement tutorials I have seen ! But there are 2 issues, first objects starts flying towards camera if I stop moving my mouse, 2nd issue might be related to the first problem, object seem to rotate on random axes rather then Y, because it only happens when object start flying towards camera view... placement system only seems to work if you don't rest mouse pointer on same place but keep moving it over map
This is so straight to the point. amazing! You know that a guy is an expert when he explains something that seems to be hard, in the simplest existing way! Thanks!
Holy shit this video is amazing. You explain EXACTLY what you need to do in order to create the basics of a city builder/tower defence. Thanks my man!!
Excellent tutorial, worked like a charm. Just one thing that I was stuck on for awhile yet managed to fix. If you create a new player and add a new camera to that one. You will need to set the Tag on the new camera to "Main Camera" or else the script won't manage to find the mousepointer/Cameraview/know where the Raycast will go.
This my friend has saved my game. This is exactly what I have been needing to see and find. Subscribed and liked. PS: I hate how easy you made this look but in the same breath I love you...lol Thanks again!
A little late, but maybe add a trigger on the placed object that recognizes if it collides with another object with the same tag (for example). You make an OnTriggerEnter check for collisions with the same object type, and then make the placement function disabled if it does collide. (Sorry for the poor explanation)
@@captainoblivious_yt I used the same method but I always wondered how performant this is. Another approach I tried was using a dictionary to save the occupied spaces. This should have been pretty efficient but idk if it was even worth it since it did create other problems (having to do more work being one of them ).
Hey, thanks for an informative video. This helped me a lot in a school project. I'm trying to figure out how I would be able to place the currentplacableobject on top of an already placed object, as it is now it goes right through it even though I added a mesh collider to the objects I place.
I always start out seeking my solution with a basic search. I typically randomly click on your videos, see your face, and go. "OH! I LOVE THIS GUY!" *goes to hit subscribe* -already subscribed.
Thank you so much for making this tutorial, now I wonder how to implement this into an online experience. Even a lan version or couch coop would be cool
First of thanks a bunch Jason for the great tutorial and you made a function I though would be hard look easy, even though I need to make some customisations to it in order for it to work in my project. I have an issue where the FromToRotation or if it's the Instantiation of the prefab turns the prefab in the wrong direct/rotation, I'm new to game development and have a hard time understanding all the transforms and math in it. I'm working with a project where you should be able to only place the currentPlacableObject on a specific layer or object (wall), but lets say it's a cube and I want to be able to place the object on each and every side of the cube with the specific rotation of the prefab, any thoughts?
Great tutorial! I am having trouble instantiating a new object that matches the mouseWheel rotation. I have a "ghost" prefab that I am dragging around and it rotates beautifully BUT when I click to instantiate the real building (not the ghost) everything is great EXCEPT the mouseWheelRotation += Input.mouseScrollDelta.y; value. Any help would be much appreciated. Thank you for your very informative videos. They have helped me tremendously!
More than helpful. I'd love to know how to use this script to snap the game object to a grid if you ever have the time and enough requests. Thanks again.
this video was really helpful even after 3 years! only issue im facing right now is that when im trying to put a prefab/ game object that has a rotation, it doesnt rotate the way that it is pre-set, it always resets to the Vector3.up rotation im guessing. i cant think of how to fix it. but thank you for the video it was just what i needed :D
it was becuz of the anchor points of the models, i fixed it in blender. now im trying to make it so that a model doesn't build if it collides with another and also that you can build models on top of eachother but idk how :/
Add a LayerMask. Every object in the scene is in the default layer, so the raycast is hitting the camera too. Just declare the public layermask at the top so you can set it in the inspector, create a new layer (I called mine placeableTerrain), and add the layermask to the raycast. Remember to put the surface you're placing on into the layer that you created public LayerMask HitLayers; --------------------------------------------- if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, HitLayers)) {
Amazing tutorial and information about the codes. Does this work for first person too? I can't seem to get mine to work because the prefab forces itself to spawn with its coordinates in Unity rather than the camera on my player.
it's finding the collider on the object, make sure the layers are correct and it's ignoring the object you're trying to move (usually with the layermask)
Nice vid, love the way you explain it, with so much ease! i seem to be having an issue tho, when the object i want to place spawns it keeps moving towards the screen and then it starts looping, what could be the problem here?
Hey I know you commented this a long time ago but I had the same issue, incase you never knew how to fix it, removing the box collider from the prefab I was placing worked for me.
I'm guessing that you have to check when you move the object with the mouse if there's another object or a collider nearby, then make some visual (red) or disappear the held item (or throw a debug.log/print as a start). oh that's when "hovering" you need another check when the user tries to "pin" (?) the item back into the world and give some kind of text error. another solution that I just thought of is when placing the object to turn the mash/collider on. actually this might be a better solution since if you have moving objects in-game (say people or the like) then they probably shouldn't collide with the mouse moving object...
Something that i came across: If your prefab is launching itself towards the camera, just simply disable the prefabs collision. Should work as intended there after!
Can you do a tutorial about game set up? For example, before getting into the game world, you set up the game by naming your person, setting difficulty, among other options and have the game use those options that you selected when you get in the game world.
I'm struggling so much in my game at the moment, i need help desperately! I'm trying to create a save system that records the position and rotation of building pieces, the building pieces are scriptable objects and I instantiate them in as game objects, but I can't for the life of me figure out how to record and store game objects values and then load them again. so that a player can build a house and then when they load up again they're still there, please would you help me?
Thank you Jason, great video. I have two problems though, My raycast doesn't seem to line up with my camera? it shows the prefab on the ground but its not where my mouse is? Secondly, All of my prefabs seem to be rotated by 90 when they appear? If anybody has any suggestions they would be greatly appreciated please!
For anyone having this problem, your pivot point is set to center on your object. Either export with your pivot point where you want it or, parent to an empty with the desired pivot point.
Not sure if you're still checking the comments for this but I thought I'd ask anyway. This video is awesome, but my problem is that (unlike the other guy in the comments) I'm not sure how to get it so that I can place objects on top of other objects that have been placed. I can do it, but then I have the layer raycast problem where the object flies at me. If I ignore the raycast for that object, I can no longer place other objects on top of it once I place it. Any solution to this?
In that case, I'd put the object onto a different layer while it's in 'placement mode', then switch it to the correct layer once the user clicks and places the object. That way it can be ignored while you're moving it around and getting it in position.. but still placed upon once it's down. Hope that made sense :)
Does anyone have a solution for the problem with the object moving to camera? I tested it out and these are my layers: i.imgur.com/CToUeWE.jpg It works now!
If you haven't fixed it yet, you have to set the object's layer to "ignore raycast" (there's also another method that seems a bit more complicated but probably works better, go look for admiral moo)
Hi!! Thanks for this great tuto!! But when the object has a Box/Mesh Collider, it doesn't work very well, with an odd glitch! Do you have any tip or suggestion to avoid this ? Thanks again!
What was the glitch you saw? One possible problem would be that the pivot point of those objects by default is the center, and for sticking to the ground, you generally want it at the bottom center.
Hard to see here, but my building is making an "epileptic crisis" : image.noelshack.com/fichiers/2017/39/7/1506891799-a-effacer.jpg Ahah ! Thanks for advice, I tried to remove the pivot point, but it makes the same effect :'( . Another thing, I tried to apply this to an animal with RigidBody, Box Collider ad NavMesh Agent, and it made something odd too, my animal passed below the ground! I think it's pretty complex to fix, but I wanted to warn you of this problem I've encountered! Never know! Thanks for the very quick reply!
If it looks like the object is coming right at you, it may be the layer issue. (the raycast has to ignore the layer the object being placed is on or it'll keep moving toward the camera and eventually pop back to the ground repeating the process infinitely)
Can anyone help me out here please? Everything works perfect but I need to make it work on a certain radius from my player. Any ideas? Thanks Jason for your tutorial!
Wow... the best explained I've seen! I know this is 5 years old at this point, but, why to some games/devs opt to do a grid placement/limited rotation instead of freeform like this? Is there a resource advantage to it?
Overall a great tutorial! I'm only having one problem - I used just a normal cube as my placeable object, but when I place the cube, it places the center of the cube where my mouse position is. I can't seem to figure out how to go about fixing this.
@@joonauutela581 You could do that, or simply parent the cube to an empty gameobject that is placed at the very bottom of the cube's geometry, then just use the parent gameobject as the placeable object.
I need help. After creating it with "z", it does not attach to the mouse cursor like what the guy has in the video, instead, it always goes to the same spot on the map, and hitting left click with the mouse places it no matter where the cursor is. its being created where I last had it on the map. I had to put the image on the map first so I can adjust the size. I did everything that was in the video. im using Unity 2d if that helps.
Awesome tutorial! I wish I was as fluent as you. Any chance you could show how to create a UI system that would allow the player to configure customized commands to control an avatar?
I have this working, apart from that my models are taking a good 10 seconds or so to appear after I press the button. Does anyone have an idea what's caused this? Great Tutorial by the way, even 3 years later!
I figured it out. I was using some free assets fromt the Unity Asset Store which came with animation components. I went into each FBX in my assets and under the 'Animation' tab, I un-ticked 'Import Animation'. My prefabs load instantly now!
(havent actually seen the video, so you should take this response with a grain of salt.) You could make a collider on the prefab and then make it unplaceable or something, when 2 objects collide. Maybe mark the placing object with red for visual representation.
When I try placing the object it starts floating to me me indefinitely. I read some comments below that I need to disable 'Generate Colliders' on the object, but I also want to be able to drag and drop the object after it's already been placed, which requires it to have 'Generate Colliders'. Is there any way around this, or do you know if there are any other scripts where I can drag and drop the object after it has been placed without 'Generate Colliders' ticked on? I would appreciate it very much if you could help. Thanks :)
Add this line under the Instantiate line: currentPlaceableObject.layer = LayerMask.NameToLayer ("Ignore Raycast"); and this one above "currentPlaceableObject = null;" currentPlaceableObject.layer = LayerMask.NameToLayer ("Default"); My buildings need to receive clicks after they're placed, so I can't just keep them on ignore raycast
I have this problem as well. it's because the object is being placed upon itself because it has a mash (a collider) one solution is to make sure that the ray only hits say object with tag ground or buildable. There is a better solution then tags (because tags causes a performance issue if you use lots of them) that I've seen on youtube but it went over my head and I don't remember it.
So I used your code and for the most part it works. However the prefab I'm using rotates rapidly and floats toward me when I press the build hot key. Any suggestions?
Thanks for pointing this out, just fixed it. Here's the link btw: unity3d.college/2017/08/02/how-to-create-a-unity3d-building-placement-system-for-rts-or-city-builders-let-your-player-place-a-3d-object-in-the-world/
Unity3d College I actually ended up at that page late last night trying to solve the problem mentioned below. I don't want to bother you with it though because I just used your code as a base and have modified it a bit. Thanks for the update and the swift reply though!
It's almost a crime that this video only has 1.8k views. Perfectly explained, very well done and completely solved my problem. thank you very much. Liked and subscribed.
lol thanks :)
that be true message from pirate sailor
me, watching it 3 years later seeing this video got 38k views happy it got more attention: yes
Amazing and informational. Really easy to follow. Thank you for a great tutorial! Had some issues, but I solved them by looking through most comments here:
I managed to solve the issue with the object flying towards the camera when pressing the key, by changing the layer of the object prefab to "Ignore Raycast". If you need it on Default, you can set it to be on default layer right before making the current selected object null. This way, you cannot place other objects on this object. However, I suggest doing some proximity calculations to not be able to place an object near certain colliders (other buildings, props).
Another issue was my object sinking halfway into my terrain. I changed its pivot point to be right on the bottom of the object in Blender.
My god this comment needs more likes it solved my problems
fr this was really helpful ty :D
literally wasted an hour trying to fix that until i remembered to check comments lolol, thanks a tonne ^_^
Thanks. I thought the shuddering effect was that the origin problem, and you can fix the origin problem in Unity by making the prefab a parent of an empty and setting the origin of the empty to 0. Saves a trip into Blender. Cheers!
OH MY GOODNESS YOU SAVED MY LIFE
Even years later, this is still a wonderful video to get object placement and rotation up and running. What a gem!
Worked for 3rd person?
@@janakisundaram3502 yep, works for my 3rd person camera as well
@@brandonellis9060 For the its cloning the object on the same place, I could not able to move as like in the video
yeah I agree with previous comment, this is one of the best placement tutorials I have seen ! But there are 2 issues, first objects starts flying towards camera if I stop moving my mouse, 2nd issue might be related to the first problem, object seem to rotate on random axes rather then Y, because it only happens when object start flying towards camera view... placement system only seems to work if you don't rest mouse pointer on same place but keep moving it over map
This is so straight to the point. amazing! You know that a guy is an expert when he explains something that seems to be hard, in the simplest existing way! Thanks!
Holy shit this video is amazing. You explain EXACTLY what you need to do in order to create the basics of a city builder/tower defence. Thanks my man!!
5 Stars rating. It solved my long time problem. Explanation is very clear and detailed. Thanks for sharing this video.
this is a crime that you got so low subscribers count! Great material and awesome knowledge base! Thank you for sharing!
This had to be one of the best explained videos
Excellent tutorial, worked like a charm.
Just one thing that I was stuck on for awhile yet managed to fix.
If you create a new player and add a new camera to that one. You will need to set the Tag on the new camera to "Main Camera" or else the script won't manage to find the mousepointer/Cameraview/know where the Raycast will go.
This my friend has saved my game. This is exactly what I have been needing to see and find. Subscribed and liked. PS: I hate how easy you made this look but in the same breath I love you...lol Thanks again!
How do I prevent the placed objects from being placed in the same place?
A little late, but maybe add a trigger on the placed object that recognizes if it collides with another object with the same tag (for example). You make an OnTriggerEnter check for collisions with the same object type, and then make the placement function disabled if it does collide. (Sorry for the poor explanation)
Captain Oblivious , well thank you, I solved it a while back the exact same way. at least new people who come here have an answer :)
@@captainoblivious_yt I used the same method but I always wondered how performant this is.
Another approach I tried was using a dictionary to save the occupied spaces. This should have been pretty efficient but idk if it was even worth it since it did create other problems (having to do more work being one of them ).
Hey, thanks for an informative video. This helped me a lot in a school project. I'm trying to figure out how I would be able to place the currentplacableobject on top of an already placed object, as it is now it goes right through it even though I added a mesh collider to the objects I place.
this was precisely what i needed, it was so difficult finding this kind of building tutorial. Thanks!
how can i prevent the prefab rotating like crazy when placed over a pointed ground?
I always start out seeking my solution with a basic search. I typically randomly click on your videos, see your face, and go. "OH! I LOVE THIS GUY!" *goes to hit subscribe* -already subscribed.
Thank you so much for making this tutorial, now I wonder how to implement this into an online experience. Even a lan version or couch coop would be cool
When I use the mouse wheel to rotate the object, it just keeps spinning and spinning :P
First of thanks a bunch Jason for the great tutorial and you made a function I though would be hard look easy, even though I need to make some customisations to it in order for it to work in my project.
I have an issue where the FromToRotation or if it's the Instantiation of the prefab turns the prefab in the wrong direct/rotation, I'm new to game development and have a hard time understanding all the transforms and math in it.
I'm working with a project where you should be able to only place the currentPlacableObject on a specific layer or object (wall), but lets say it's a cube and I want to be able to place the object on each and every side of the cube with the specific rotation of the prefab, any thoughts?
For me this solved the issue:
currentPlaceableObject.transform.rotation = Quaternion.FromToRotation(new Vector3(0,0,90), hitInfo.normal);
This is exactly what I was looking for, thank you so so much !!!
Me too
how to make an object stay on the ground while moving using a mouse ?
I really love the tutorial but can you make like an updated version with a build countdown? or can somebody tell me how I can implement one?
Hey Jason - great video, very clear, and solved the problem of placing turrets in my new game. Thank you for doing these!
how can i make the blocks rotate exactly 90 on key press instead of free rotation like with the middle mouse scroll
Awesome video man, very informational!
can u plz make tutorial for how to make roads and path like anno 1800
thanks
How do I then "select" and then delete those turrets/towers that I have dropped in game?
Great tutorial! I am having trouble instantiating a new object that matches the mouseWheel rotation. I have a "ghost" prefab that I am dragging around and it rotates beautifully BUT when I click to instantiate the real building (not the ghost) everything is great EXCEPT the mouseWheelRotation += Input.mouseScrollDelta.y; value.
Any help would be much appreciated.
Thank you for your very informative videos. They have helped me tremendously!
Brilliant tutorial! This is the first one that has actually worked for me. Liked and subscribed. Thanks very much for your work!
Great! Glad it was helpful! :)
More than helpful. I'd love to know how to use this script to snap the game object to a grid if you ever have the time and enough requests. Thanks again.
this video was really helpful even after 3 years! only issue im facing right now is that when im trying to put a prefab/ game object that has a rotation, it doesnt rotate the way that it is pre-set, it always resets to the Vector3.up rotation im guessing. i cant think of how to fix it. but thank you for the video it was just what i needed :D
it was becuz of the anchor points of the models, i fixed it in blender. now im trying to make it so that a model doesn't build if it collides with another and also that you can build models on top of eachother but idk how :/
when i press A the object is flying towards the camera over and over again, what did i do wrong?
Add a LayerMask. Every object in the scene is in the default layer, so the raycast is hitting the camera too. Just declare the public layermask at the top so you can set it in the inspector, create a new layer (I called mine placeableTerrain), and add the layermask to the raycast. Remember to put the surface you're placing on into the layer that you created
public LayerMask HitLayers;
---------------------------------------------
if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, HitLayers)) {
@@AdmiralMoo thanks! you saved me
Amazing tutorial and information about the codes. Does this work for first person too? I can't seem to get mine to work because the prefab forces itself to spawn with its coordinates in Unity rather than the camera on my player.
Simple and the most import straight to the business…. awesome. Liked and sub!
Why is it that when placing an object it is dragged to the camera?
it's finding the collider on the object, make sure the layers are correct and it's ignoring the object you're trying to move (usually with the layermask)
Nice vid, love the way you explain it, with so much ease! i seem to be having an issue tho, when the object i want to place spawns it keeps moving towards the screen and then it starts looping, what could be the problem here?
Hey I know you commented this a long time ago but I had the same issue, incase you never knew how to fix it, removing the box collider from the prefab I was placing worked for me.
you should probably add Terrain keyword on the video so that people find it ( it took quite a time to find such a video)
how do I prevent objects being placed on the same place, I tried with colliders but its just making the objects fly and move randomly.
I'm guessing that you have to check when you move the object with the mouse if there's another object or a collider nearby, then make some visual (red) or disappear the held item (or throw a debug.log/print as a start).
oh that's when "hovering"
you need another check when the user tries to "pin" (?) the item back into the world and give some kind of text error.
another solution that I just thought of is when placing the object to turn the mash/collider on.
actually this might be a better solution since if you have moving objects in-game (say people or the like) then they probably shouldn't collide with the mouse moving object...
Hi Jason, what would you need to add to prevent the clones from overlapping?
maybe use colliders as trigger to see if there is another collider blocking the spot.
I don't understand why but when i click A, the prefab start to make a repeat movement [planeposition to camera and back] How can i fix this ?
Remove collider
Awesome tutorial, Helped me a lot and the way you describe everything was very nice. Easy to follow. needs more likes!!!!!
Thank You for the knowledge, Jason.
Hey can we make it for Scene prefab building like prefab brush ?
Something that i came across: If your prefab is launching itself towards the camera, just simply disable the prefabs collision. Should work as intended there after!
Can you do a tutorial about game set up? For example, before getting into the game world, you set up the game by naming your person, setting difficulty, among other options and have the game use those options that you selected when you get in the game world.
I'm struggling so much in my game at the moment, i need help desperately! I'm trying to create a save system that records the position and rotation of building pieces, the building pieces are scriptable objects and I instantiate them in as game objects, but I can't for the life of me figure out how to record and store game objects values and then load them again. so that a player can build a house and then when they load up again they're still there, please would you help me?
Thank you Jason, great video.
I have two problems though, My raycast doesn't seem to line up with my camera? it shows the prefab on the ground but its not where my mouse is?
Secondly, All of my prefabs seem to be rotated by 90 when they appear?
If anybody has any suggestions they would be greatly appreciated please!
I, i like this. U think is possible to make this tutorial with snap to grid ? :p
how to make it work in third person controller
Why my object glitch in the terrain, its only half of my object can be seen? its already have terrain colliders, etc.
For anyone having this problem, your pivot point is set to center on your object. Either export with your pivot point where you want it or, parent to an empty with the desired pivot point.
Not sure if you're still checking the comments for this but I thought I'd ask anyway. This video is awesome, but my problem is that (unlike the other guy in the comments) I'm not sure how to get it so that I can place objects on top of other objects that have been placed. I can do it, but then I have the layer raycast problem where the object flies at me. If I ignore the raycast for that object, I can no longer place other objects on top of it once I place it. Any solution to this?
In that case, I'd put the object onto a different layer while it's in 'placement mode', then switch it to the correct layer once the user clicks and places the object. That way it can be ignored while you're moving it around and getting it in position.. but still placed upon once it's down. Hope that made sense :)
Gotcha. Hmm, guess I gotta look something up for that (I'm not too fluent just yet)
@@Qaztar44 Got any solution?
how can we get the assets you used?
How do make so i cant place on a other gameobject?
sorry for bad english
How can i make it, so when i press a button, it changes the placeableObjectPrefab? I have trouble with that.
he made another video: ruclips.net/video/MbOdWBirf1o/видео.html
you the man!
you're helping college students all over the world my man!
Does anyone have a solution for the problem with the object moving to camera?
I tested it out and these are my layers: i.imgur.com/CToUeWE.jpg
It works now!
How did you fix it?? I have the same problem
How did you fix it?
If you haven't fixed it yet, you have to set the object's layer to "ignore raycast" (there's also another method that seems a bit more complicated but probably works better, go look for admiral moo)
Hi!! Thanks for this great tuto!!
But when the object has a Box/Mesh Collider, it doesn't work very well, with an odd glitch! Do you have any tip or suggestion to avoid this ? Thanks again!
What was the glitch you saw? One possible problem would be that the pivot point of those objects by default is the center, and for sticking to the ground, you generally want it at the bottom center.
Hard to see here, but my building is making an "epileptic crisis" : image.noelshack.com/fichiers/2017/39/7/1506891799-a-effacer.jpg
Ahah ! Thanks for advice, I tried to remove the pivot point, but it makes the same effect :'( . Another thing, I tried to apply this to an animal with RigidBody, Box Collider ad NavMesh Agent, and it made something odd too, my animal passed below the ground! I think it's pretty complex to fix, but I wanted to warn you of this problem I've encountered! Never know! Thanks for the very quick reply!
If it looks like the object is coming right at you, it may be the layer issue. (the raycast has to ignore the layer the object being placed is on or it'll keep moving toward the camera and eventually pop back to the ground repeating the process infinitely)
Thanks a lot, it seems to work, sorry, I'm a really beginner, I suscribe immediatly to your channel :* ! Thanks again !
Awesome, glad that worked :)
Would this work with a first person controller?
it does for me
Can anyone help me out here please? Everything works perfect but I need to make it work on a certain radius from my player. Any ideas? Thanks Jason for your tutorial!
You can use hitinfo.distance and check with an if statement if the distance is bigger or smaller than a value.
or just add a ", yourfloat" after the hininfo. To define the max. length of the ray.
Check the distance of the raycast, and do a if(hitInfo.distance < 10f), then run the code. Then just do an else { return; }
Wow... the best explained I've seen!
I know this is 5 years old at this point, but, why to some games/devs opt to do a grid placement/limited rotation instead of freeform like this? Is there a resource advantage to it?
Can you please make something that you could swap between prefabs? It would mean a lot to me 😁 really good tutorial by the way
Here ya go: ruclips.net/video/MbOdWBirf1o/видео.html
Another very useful Tutorial.
Thx!
Nice tutorial, thanks for this little lesson :)
Overall a great tutorial! I'm only having one problem - I used just a normal cube as my placeable object, but when I place the cube, it places the center of the cube where my mouse position is. I can't seem to figure out how to go about fixing this.
you need to recalculate the y-coordinate using your cubes y-scale divided by two.
@@joonauutela581 You could do that, or simply parent the cube to an empty gameobject that is placed at the very bottom of the cube's geometry, then just use the parent gameobject as the placeable object.
I need help. After creating it with "z", it does not attach to the mouse cursor like what the guy has in the video, instead, it always goes to the same spot on the map, and hitting left click with the mouse places it no matter where the cursor is. its being created where I last had it on the map. I had to put the image on the map first so I can adjust the size. I did everything that was in the video. im using Unity 2d if that helps.
Instead of using vector3 use vector2, you might also have to fix some other code but that’s the simplest answer I can give uou
Great! I wanted to know this one!
The only bad thing is the nostril camera. Thanks for the excellent tutorial!
Great tutorial! But I have some issues. When I used game object that have Rigidbody / Collider, it goes up! Help please...
Make your prefab's layer on "Ignore Raycast" than you can enable colliders.
Awesome tutorial! I wish I was as fluent as you. Any chance you could show how to create a UI system that would allow the player to configure customized commands to control an avatar?
this tutorial was easy to follow and had a great outcome.
Thank you so much!
I have this working, apart from that my models are taking a good 10 seconds or so to appear after I press the button. Does anyone have an idea what's caused this?
Great Tutorial by the way, even 3 years later!
I figured it out. I was using some free assets fromt the Unity Asset Store which came with animation components.
I went into each FBX in my assets and under the 'Animation' tab, I un-ticked 'Import Animation'. My prefabs load instantly now!
How would I make it that you can't place buildings on buildings
In
(havent actually seen the video, so you should take this response with a grain of salt.)
You could make a collider on the prefab and then make it unplaceable or something, when 2 objects collide. Maybe mark the placing object with red for visual representation.
When I try placing the object it starts floating to me me indefinitely. I read some comments below that I need to disable 'Generate Colliders' on the object, but I also want to be able to drag and drop the object after it's already been placed, which requires it to have 'Generate Colliders'. Is there any way around this, or do you know if there are any other scripts where I can drag and drop the object after it has been placed without 'Generate Colliders' ticked on? I would appreciate it very much if you could help. Thanks :)
Make your prefab's layer on "Ignore Raycast" than you can enable colliders.
Thx Tarik
Thank you so much! Tarik
Add this line under the Instantiate line:
currentPlaceableObject.layer = LayerMask.NameToLayer ("Ignore Raycast");
and this one above "currentPlaceableObject = null;"
currentPlaceableObject.layer = LayerMask.NameToLayer ("Default");
My buildings need to receive clicks after they're placed, so I can't just keep them on ignore raycast
thanks heaps
@@tarikhusny7116
whys is my Object Levitates from the hitpoint to the center of the camera, hoping for reply, thanks.
I have this problem as well. it's because the object is being placed upon itself because it has a mash (a collider)
one solution is to make sure that the ray only hits say object with tag ground or buildable.
There is a better solution then tags (because tags causes a performance issue if you use lots of them) that I've seen on youtube but it went over my head and I don't remember it.
@@shachar2 thank you for reaching out. I somehow tried your idea by using Layer instead of Tag, and it works the way i wanted now.
@@jiyu4149 well mates i have same problem xD my Object is levitating above ground and causes strange glitches any way to solve ?.
So I used your code and for the most part it works. However the prefab I'm using rotates rapidly and floats toward me when I press the build hot key. Any suggestions?
It sounds like you're missing the layer / layermask and the placement ray is hitting the object. Can you check that?
@@Unity3dCollege having the same issue, but in your video i cant see which layer / layermask i could miss ? all your layers are default
i have the same issue
Cool stuff!! Man
Hey not seeing any links or source in the description
Thanks for pointing this out, just fixed it. Here's the link btw: unity3d.college/2017/08/02/how-to-create-a-unity3d-building-placement-system-for-rts-or-city-builders-let-your-player-place-a-3d-object-in-the-world/
Unity3d College I actually ended up at that page late last night trying to solve the problem mentioned below. I don't want to bother you with it though because I just used your code as a base and have modified it a bit. Thanks for the update and the swift reply though!
My object move up, i don't know how i can fix that
If you'd like to zip up your project and send it to me I can see what's going on. jason @ unity3d.college
Made it, thanks
I have the same problem? the object keeps flying towards the camera. Any fix?
Yep, thanks Unity3d College, He tell me the issue, you need to disable te object collider ;)
Thanks that helped!
Thank you!
wtf my object that i want to place in the ground is coming over to my camera hahaha how to fix that?
Same thing is happening to me. Could you help us out?
@@vancedk16 it's simple, make sure the prefab object has the tag Ignore Raycast
@@vancedk16 you don't have to create one, it's already created, find it on the tag list
my rotation is getting reset and you never fixed it....
why you are the best :)
Ooops! I just forgot to set the layerMask.... problem solved.
Awesome!
He didnt mentioned any layermask
Thanks!
coool!
Oh snap! Green screen.
7:05
Dude I subbed! you are fckin good!
❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤
For mobile please bro. Thank you!
I'm a year late but....are you asking for a tutorial for mobile or what? Because if so, why would you try to make a game with a phone?
Just a tip, Lose the face cam! it's off-putting, because this is a semi-tutorial, it isn't needed
Thanks!