- Home /
2D game with 360 degree aiming and shooting a particle system... help please
I've seen similar questions as this one, but none of the answers I've seen apply to this particular situation. I'm using the 3d platformer (Lerpz) tutorial to test out a few gameplay features that I want in my game prototype. I'm having trouble creating telekinesis powers. Right now, I have the particle system shooting when I click the mouse, but it's just going in the positive x axis, since it's using the particle system's velocity... I want it to go wherever I'm clicking the mouse. I think I have a handle on the steps to complete this, but I'm looking for similar scripts since I'm not used to C# or JS. This seems like a fundamental need for anyone make a side scrolling game, so I'm surprised I haven't seen many good answers or threads yet.
I assume the steps go:
Create a particle system then put it in a game object then make it a child to the player so it moves with it. (Done)
Make the mouse cursor the aiming point/crosshair. (I only know how to do in a FPS)
Make a script or somehow get the particles to shoot at the location where I'm pressing the mouse (no idea on how to do this)
Add force to the particle system so it pushes objects. (I think I have an idea on how to do that)
Update: The question is still unsolved since the other method was a no go.
I have your answer , I was interrupted and now stuck in workshop!! I will post a full step plan soon ok to get the vector you need, hang in there! :D
And don't bother with particles yet , start with Destroy(Instantiate());
Answer by Proclyon · Nov 01, 2010 at 02:30 PM
I am glad you are asking this question! I have been doing exactly the same trying to build a firing crosshair based 2D element into my project!
Ok , so you need to shoot at a specific target point with a cursor on your screen in a 2D environment without using to much trigonometry. That I can help you out with.
To build the crosshair go to GameObject --> Create Other --> GUI Texture, name it crosshair and then create a C# Script (I prefer C#, not required but I can't explain it in JS I'm afraid)
Create the script doing Assets --> Create --> C# / JS Script
You also have to make your crosshair on a part of your GAME screen and NOT your VIEW screen. Your screen is irrelevant to the game and 50% of the game screen in windowed mode will not be 50% of you screen. I suggest you take a % value of the screen by getting the mouse information. Unity scripting has a getter for that Screen.width and Screen.height use them for the GAME window sizes (Wish I Could just post the code....)
For shooting you will need the coordinates!
I help you get started with that but I have not got it working yet since spawning an object with Instantiate has an origin but not a Target , it works with forces so I'm still looking for a way out without Trigonometry or somehow creating a force value with the Vectors that matches the direction it would go X and Y wise so it's be exactly what u were looking for.
So far I have been trying these following things: Extrapolate the original vector using the transform of the object (gun or something else that shoots as long as that's the object the ammo should be coming out of), You may need to fiddle with the offset later Create the target Vector with transform.TargetDirection( x_value , y_value , 0.0f )
This will give you the locations and now you can just LERP (Linear Interpolation(Connect the dots in straight line with 2 dots)) the two together but that's where the help stops. I still have to do that myself aswell.
I tested the vector info and it works perfectly in all screens and resolutions for me!
<<<
I had intended and finished posting the full code samples which would save you about a day of work , but I just asked and that is pretty much "Not done" , I apoligize for getting your hopes up, but IP = IP :( it's that or get in a LOT of trouble for me and my work here, so I hope this stripped down crappy answer will get you on your way. It's probably ok for me to link POST-production but by then it's probably to late.
F.Y.I. I am 100% Anti IP, can't help it TODAY. But I keep trying ^^ Knowledge4All
<<<
Thanks for your reply, things are a little bit clearer now. I sent you a P$$anonymous$$ on the Unity (forum) site, since I have a question regarding what you said and it working with the particle system.