I'm just wondering how to make shots in my game more realistic. I mean there are two main ways in implementing shots. First: throw a small projectile and let it detect collisions. Second: use raycast. But in real world (and apparently I noticed this in PUBG) bullets fly really quick but not immediately. Here is why you should aim near your target if it's far away from you to hit it. Because if you aim right where it is it will move and your bullet will miss the target.
I'm just curious if any of you, guys have a nice solution to this problem. Also I wish to find a way to use raycast not every frame. In such things like detecting if you will actually hit the wall when shooting. If you have any good ideas how to implement spread and recoil for different types of weapons I will be happy to read them.
Blue point is bullet point of frame. and in very frame send a new raycast to check cross any human. like red line in this picture.
and bullet path use unity built-in Physics system to do it.
I am building a game in XNA 4.0, where a player moves about a 2 dimensional (vertical perspective) map consisting of blocks. My issue is creating proper collision between the payer and the blocks (basic game physics.) The player moves more than 1px per frame, so .Intersects() just isn't enough, I need physical contact collision that can function in a gravity environment. The current version I currently have is a piece of garbage and only works occasionally.
Basically, all that the collision system needs to do is stop gravity when the player lands on a block, and provide some decent physics when the player hits blocks (movement in that direction ceases). The idea behind my current solution is to move the next Position around until it finds a clear spot, but it doesn't work well. I have an idea why, just have no idea how to do it properly.
I know there must be a better way to do this. What would be the best method of making this kind of collision work properly?
Thanks
This does the job perfectly, you just need to sort through a few syntax errors. http://go.colorize.net/xna/2d_collision_response_xna/
I'm currently working on my FPS game and going to make bullet holes(decals) but google doesn't help me at all. I cannot find the shader or any source that explains how to. If anyone did something like this one please help. Thanks in advance.
I take it you are casting a ray when you shoot? This way you can detect where it collides with a wall. If you have not done this, you should start there. When you know where the ray hits the wall you can create a flat plane on top of the geometry with your bullet hole texture on it including a alpha texture.
I have been coding for some years in C# and have now decided to try out the XNA framework to make games.
It went great until I started to implement collision handling in my very simple game.
I can understand how to do collision detection using BoundingBoxes and BoundingSpheres, but after looking at the refresh rate in my game, it quickly became a concern of mine if the two colliding objects were never detected as colliding.
Let me try to explain with an example:
- If a character is shooting with a gun at another character.
- The bullet is heading straight for the other character.
- The bullet gets rendered just before the character.
- Because of the bullets high velocity it now gets rendered on the other side of the character.
In this scenario the bullet and the character never collides, because they are never rendered in their colliding state.
So how do you make sure to detect a collision in this scenario?
For very fast-moving objects, the regular approach fails in the scenario you described. What you need to check for is whether the bullet has collided with any item in the interval between the two consecutive game ticks. This is called continuous collision detection (this is a rather related SO post).
You can do this by basically casting a ray between the middle of the bullet's binding box in the current position and the middle of the box from the old position, and checking if that collides with any other blocks/spheres. This is a rather fast solution and if your bullets are small enough, it should work fine.
For more precision, you can cast four different so-called collision rays from each corner of the current bullet box, to their corresponding positions from the previous game tick. Note that in the rare event of high-speed items smaller than bullets, this might also fail. In this case you would need a more advanced collision detection system. But this would just be a corner case.
If that extra precision is a must, a free 3D physics library, such as Bullet could represent a solution. It even has bindings for XNA!
I think your problem is in tunneling that matches your description.
I recommend you to use Box2D physics engine for XNA. It's fast, simple and will avoid your any problems with collisions in your game.
Check in this manual on 4th page continuous collision and check how Box2D deal with tunneling effect.
I am going to make a game like XNA example game "Platformer1" which comes with the XNA. But I need longer levels which doesn't fit in the screen (like Super Mario levels). How can I manage this kind of level? Do I need to use a 2d camera that follows the sprite? If I do this way how can I load the level? I am a bit confused and I am not sure if I could explain my problem clearly. Hope someone can help?
The tutorial based on Platformer Starter Kit in MSDN has a step Adding a Scrolling Level which guides you through creation of longer levels. The tutorial is very detailed, I highly recommend it.
I couldn't find the tutorial in the section for XNA Game Studio 4.0, but differences should be minimal. According to the comment at the bottom of the page, all you need to change is replace
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None, cameraTransform);
with
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise, null, cameraTransform);
in the tutorial code.
If you want to create a side scrolling game, then I would look into parallax scrolling. A quick google/bing will help you find lots of tutorials. Also, another useful tip is to search YouTube for XNA videos has we a lot of posters share their source code .
Here is a link to Microsofts Parallax Scrolling.
Sounds like you have a few problems ahead of you.
But I need longer levels which doest'n fit in the screen(like super mario levels). How can I manage this kind of levels.
There are several ways to do this, but a fairly easy way would be to have a 2d array (or sparse array, depending on how large your levels are) of a class named Tile that stores info about the tile image, animation, ...whatever.
Yes, you'll probably want a "camera". This can be as simple as only drawing a certain range of that array or a more featured camera that uses transforms to zoom out and translate across your level.
Hopefully this will help get you started.
I've done a decent amount of work in XNA, and from my experience, there are 2 ways to draw a 2D scene:
1) Strictly 2D. This method is much easier, but has a few limitations. There is no "camera" per se, what you do is move everything underneath the fixed 2D "camera". I say "camera" in quotes because the camera is fixed (as far as I know). The upside is that it's easy, the downside is that you can't easily zoom in or out or do other camera effects.
2) 2D in 3D. Set up a 3D world with a 2D plane. This is more flexible, but is also more challenging to work with because you will need to set up a 3D world and 3D camera. If this is your first attempt with making a game, I would highly recommend against this method.
I'm really only familiar with the strictly 2D method, and you would want a list of map objects that have a 2D coordinate. You would also want to store which section of the map you are looking at, I do this with a Rectangle or Vector2 that stores this. This value would move forward as the character moves. You can then take your 2D map objects' coordinate and subtract the (X,Y) of the top-left of what you are looking at to determine an object's screen position. So:
float screenX = myMapObject.X - focusPoint.X;
float screenY = myMapObject.Y - focusPoint.Y;
An other thing to note, use floats or Vector2/3 to store locations, you may not think it's required now, but it will be down the line.
It might be overkill, but my SF project uses XNA to draw a Strictly 2D scene that you can move around: http://sourceforge.net/projects/asteroidoutpost/
I hope this helps.
Have a look at Nick Gravelyns tutorials. They helped me tonne when I was first starting out - Really really worth a look for learning a lot on 2D games.
All the videos are now on youtube here