Hello everyone,
I’m a total newbie when it comes to Unity. Anyway, I’m doing this game and I’ve created the terrain and everything but now I need a bit of advice. This is a 3rd person shooter game and my characters are men made of paint. I’ve used the 3rd person controller and models offered as standard by Unity because they’re perfect for the look I’m going for and what I need. But, I want to make these characters shoot each other with projectiles of paint that come out of their bodies. I also want them to color the bodies of their enemies when hitting them, or the terrain if they miss. Can you please give me any advice on how to do this?
I hope I haven’t offended you with my stupidity and thanks in advance for any help!
I’ll give you a high level overview of what you can do.
To shoot a projectile, you need a [direction][1] to your target and then either move a slow moving object object with a [rigidbody][2]/[collider][3] in that direction or cast a [ray][4] for instant/rapid fire, or a combination of both. To spawn a projectile, either a prefab is [instantiated][5] or an object is reused from an [object pool][6] for performance reasons. If you use a game object to represent your projectile, then it need to keep moving. You could just [add a force][7] to the rigidbody, or write a script that control the path exactly how you want it.
To detect the projectile hit something, typically you’d just query [Physics.Raycast][8] for instant/rapid fire type projectiles, to see what object is hit. Or use [OnTriggerEnter][9] or [OnCollisionEnter][10] for slower moving projectiles, where the projectile handles collision response after it’s been fired.
Once an object has been detected, you’d respond to the collision by applying an effect to the object that represents paint. I don’t know what specific effect you had in mind, but a simple “to get started with anything” could be to change the color of the objects [material][11]. To do this, [get][12] the [renderer]13 of the object and modify the [renderers material][15] [16]. Obviously it would not look very nice to color the entire terrain but it can be a first step. More accurate solutions use decals. Even more accurate solutions could use [shaders][17] to make paint “flow” or “drip” over the bumps and normals of the bump map. [For ideas, check out how Overgrowth did blood effects][18].~~
~~[1]: http://docs.unity3d.com/ScriptReference/Vector3.html~~
~~[2]: http://docs.unity3d.com/ScriptReference/Rigidbody.html~~
~~[3]: http://docs.unity3d.com/ScriptReference/Collider.html~~
~~[4]: http://docs.unity3d.com/ScriptReference/Ray.html~~
~~[5]: http://docs.unity3d.com/ScriptReference/Object.Instantiate.html~~
~~[6]: https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling~~
~~[7]: http://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html~~
~~[8]: http://docs.unity3d.com/ScriptReference/Physics.Raycast.html~~
~~[9]: http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html~~
~~[10]: http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html~~
~~[11]: http://docs.unity3d.com/Manual/class-Material.html~~
~~[12]: http://docs.unity3d.com/ScriptReference/Component.GetComponent.html~~
~~[13]: http://docs.unity3d.com/ScriptReference/Renderer.html~~
~~[14]: http://docs.unity3d.com/ScriptReference/Component.GetComponentsInChildren.html~~
~~[15]: http://docs.unity3d.com/ScriptReference/Renderer-material.html~~
~~[16]: http://docs.unity3d.com/ScriptReference/Material-color.html~~
~~[17]: http://docs.unity3d.com/Manual/class-Shader.html~~
~~[18]: Overgrowth Alpha 145 changes - Wolfire Games - YouTube