Unity 3d - Explosion Area Damage - unity3d

I've developed an airplane 3D shooter game. In this game, I want to make my plane shot a bomb. When the bomb gets to the enemies it will explode and give damage in the area of explosion.
I have already searched for a tutorial to make this code and the animation of explosion. But I couldn't find it. Please tell me about something that could solve this problem. I'm developing my game using C#.

For the explosion animation, you could use a particle system. There are many pre-made ones in the Asset Store, such as this one: https://www.assetstore.unity3d.com/en/#!/content/42285
For detecting what is affected in the explosion's area of effect, do a SphereCast (https://docs.unity3d.com/ScriptReference/Physics.SphereCast.html) from the point of impact and then do whatever you want with any of the objects touched by the sphere.

Related

How do I create an outline for my SKSpriteNode around the png texture in swift?

I am making a game in Swift(SpriteKit) and when the character in the game picks up a power-up, I want him to get an outline in purple so the player can see that his power-up is ready to use. I want the outline to hug all the curves of the player exactly. Is there any way to draw an outline around a sprite node that isn't a basic shape(like circle or square) but to outline a complex shape?
Here is an example of a shape similar to my sprite node:
And here is another example of the player with the visual outline that I want to add in SpriteKit(I just sketched it but I want it to be exact obviously):
They player also has his legs animating by flipping through an atlas of the animation, and preferably the outline would stay around the legs when the walking animation is happening. Is this possible?
To be clear, I just want an outline for visual purposes, so the player knows their "power up" shield is active so if they get hit it won't damage them.
I haven't dabbled with SpriteKit for a few years, and if memory serves me correctly perfect collision detection while animating is not available out of the box.
After checking the documentation I see that SKPhysicsBody has a init(texture:size:) initializer. This should at least get you a bit closer.
This guide from Apple is probably worth a read. (Pixel perfect collision detection is expensive).

Side scroller style scene with gravity

I've started learning sprite kit and I think I've got the basics but now I'm struggling with something.
I want to create a game that has a 'Streets of rage' type feel to it whereby the user can move up and down, but isn't jumping, they're still on a 2D plane. But I also want them to be effected by gravity e.g stairs etc. like the following picture.
Am I right in assuming that I should have my background image with colliders around the blue and brown edges, and then create a physicsbody collider located at the feet of my player/players so that it looks like they can move against the background, but when their feet reach the top it would stop?
Could I then place other obstacles like rocks etc on that path that they would be able to collide into, but that could also sit over the path and the sky? How would I handle the fact that these could be constantly colliding depending on the position?
I appreciate there isn't any code here, but I'm trying to understand the concept around this before I jump in coding a solution.
Thanks
I would use a categoryBitMask to separate the different planes of objects.
And I would play with collisionBitMask/contactTestBitMask depending from the plane the player is in, in addition to the z-order.
Thus you can have a rock that collides your player if they are both in the same line else the player would walk behind/front.

How to change the shooting accuracy?

I am making an FPS game using unity 3d, I've a problem in the shooting accuracy script. Can you tell me how I can change it with a single script that shoot the bullet and include the shooting accuracy and equipped to the gun, please?
If you are currently using a raycast, you should have no problem.
If you are spawning a sphere and thrusting it forwards, I suggest you use a raycast.
Raycasts go in a completely straight line. Bullets follow gravity, and quickly fall to the ground.
You don't see bullets, they move too fast. Raycasts are invisible.
When it hits something, it sends you back the information you need. If you make the sphere go too fast, it might glitch through objects.
You can learn about raycasts here.

Detecting when SKEmitterNode particle makes contact with another SKNode

Does anyone know how I can detect when an SKEmitterNode particle makes contact with a SKNode in the SKScene?
I want to apply a little force to the SKNode when a particle makes contact with it for a 2D game I'm creating.
You can't. You can't get the location, size and other properties of individual particles.
The essence of a particle system is that its particles are minimalistic and under full control of the particle system. Hence you don't normally get any access to individual particles in a game engine, mainly because it wouldn't make sense to do so.
There can be specialized particle emitters built on regular sprites where you have access to particles and where particles can have physics bodies. Solutions exist for other engines but I'm not aware of one that works with Sprite Kit. These are always slower than regular particle emitters, especially with physics enabled, forcing you to use a lot less particles to begin with.

iPhone: Camera following player in cocos2d

I'm making an iPhone game in cocos2d.
I was wondering how I would make the camera / the view follow a specific sprite?
would I use the CCCamera class?
Yes, CCCamera would work. However, it has some drawbacks that make it undesirable for some uses. Moving the layers respectively all other objects relative to that sprite may be a better solution. It depends on the game.
First, read up what the different approaches and their drawbacks are, you can get a lot out of this cocos2d forum thread:
http://www.cocos2d-iphone.org/forum/topic/5363
It would be helpful if you could describe what your game is about and why you need the camera attached to that sprite.
For example, if you're thinking of a running game like Canabalt, i would not use the camera to scroll over the world, but instead scroll everything relative to the player (towards him) with the player sticking at about the same x coordinate while running. Perfect examples of games where you would not move the camera at all are the iCopter games, they are basically simplified versions of Canabalt. Notice that the player sprite always stays at the exact same x coordinate, and the game world just scrolls
Scrolling the camera itself in my opinion makes the most sense if you have a large game world that the player can traverse in all directions, and the number of objects are simply too numerous and also moving about in various directions, so updating their positions individually each frame would be both overkill and prone to errors. And since the game world is so huge, you would want to use the camera's position to limit what is drawn on screen.
use CCFollow actions
Like these :-
[self runAction:[CCFollow actionWithTarget:(u r hero) worldBoundary:CGRectMake(0,0,1050,350)]];
it will helps