Hey i’ve got stuck on a problem in my game whereas im trying to create a “spell” which should spawn a blizzard at my mouses current location when im pressing the key.
Anyone got an idea on how to do this?
Im using JavaScript (UnityScript)
ScreenToWorldPoint, you will have to define a max distance, in the docs it uses near clip plane which is defined on the camera.
As im fairly new to unity i can’t really understand this piece of code.
The way i figured this out was if i could spawn a gameobject at my mouses current z and x position. This gameobject would define the area of where enemies are effected and also add an effect to the ability. This might not be possible but is there anyway similiar to do what i intent or do i just have to re-think?
Cheers
the main ideas behind placing something “at the mouse point in the 3d world” are:
find where the mouse is on the 2d screen
map that 2d point to the 3d world point to see where to place the gameobject
instantiate an object at that point
this is mostly covered in the example on this ref page: Unity - Scripting API: Input.mousePosition
Input.mousePosition is the 2d position bit
the raycast bit covers the 2d point to 3d world point bit (you draw a line from the camera through the mouse point and see what it hits in your scene - raycasts are very useful so worth a good look at in the reference guide Unity - Scripting API: Physics.Raycast).
the instantiate line handles the creation of an object but you’ll need to tweak that line to take the position of the “hit” from the raycast (you’ll need to look over the raycasts documentation to figure this bit out).