• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Medo Mex

Shooting Accuracy

8 posts in this topic

Hi guys,

 

In FPS game, each weapon should have different accuracy, for example: A sniper usually have higher accuracy than a machine gun or pistol.

 

I'm creating a ray for shooting from the cross hair and looking for a way to set the ray accuracy in percentage (accuracy of 100 means it will shoot exactly the same point infront of the cross hair).

 

D3DXVECTOR3 rayOrigin;
D3DXVECTOR3 rayDirection;

// Shooting
Raycasting(rayOrigin, rayDirection);

How do I update rayDirection to set the weapon accuracy?

0

Share this post


Link to post
Share on other sites
rayOrigin is the position of the gun (position vector) and rayDirection is the vector towards the ideal centre of the crosshair (direction vector), right?

Now with accuracy:
rayOrigin will be the same.
And about rayDirection - each weapon could have its precision defined as the maximum angle the shot could go off the ideal centre (for example 5 degrees).
You would generate a random number from 0 to this maximum angle and rotate the rayDirection around the rayOrigin point by this random degree lets say to the right. So, for example, if the random number was 2.1 degrees, the shot at this stage would go exactly 2.1 degrees to the right of the ideal direction.
And as the next step, you would generate a random angle from 0 to 360 degrees (so a full "circle") and rotate this new direction vector around the ideal direction vector by this amount.
As a result, the shots can go randomly anywhere around the ideal target and only by a limited (but random) distance from the target. Edited by Tom KQT
1

Share this post


Link to post
Share on other sites
rotate the rayDirection around the rayOrigin point by this random degree lets say to the right

 

So, I need to create a matrix and use D3DXVec3TransformCoord(), right?

 

How should I do the rotation according to the random degree? I usually use D3DXMatrixRotationYawPitchRoll() for rotation but not sure how you are explaining the rotation here.


D3DXMATRIX rotation;
// Rotate 2.1 degrees (random number)
// Rotate 0-360 angle
D3DXVec3TransformCoord(&rayDirection, &rayOrigin, &rotation);
0

Share this post


Link to post
Share on other sites

It should work this way. Maybe it could be done more effectively, dunno.

Anyway:

[source]

// lets presume D3DXVECTOR3 rayDirection is already defined and contains your ideal shooting direction vector

 

// first we need to find any vector perpendicular to rayDirection. There is infinite number of such vectors, we need any one of them. This could be done for example this way:

D3DXVec3 perpVec(rayDirection.y, -rayDirection.x, 0);

// when using this very simple way you would however have to make sure that you don't get 0 vector by this, which would happen if both rayDirection.x and rayDirection.y were zero. In this case you would have to use slightly different core, for example:

//D3DXVec3 perpVec(0, rayDirection.z, -rayDirection.y);

// The whole point of finding a perpendicular vector this way is to swap two components, change the sign of ONE of them and make the 3rd component zero.

 

// Normalize it for safety:

D3DXVec3Normalize(&perpVec, &perpVec);

 

// Now the shooting accuraty:

float shootingDeviationAngle = GetRandomNumberInInterval(0, maxDeviationAngleForCurrentWeapon); // this is partly pseudo-code, but I think it's clear what it does. Values are in radians!

 

// Rotate vector rayDirection around vector perpVec by the shootingDeviationAngle angle:

Matrix m;

Vec3 v;

D3DXMatrixRotationAxis(&m, &perpVec, shootingDeviationAngle);

D3DXVec3TransformNormal(&v, &rayDirection, &m);

 

// Get a random angle from 0 to 360 degrees:

float angle = GetRandomNumberInInterval(0, D3DX_PI * 2.0f);

 

// And rotate vector v around vector rayDirection by this angle:

D3DXMatrixRotationAxis(&m, &rayDirection, angle);

Vec3 finalRayDirection;

D3DXVec3TransformNormal(&finalRayDirection, &v, &m);

[/source]

Edited by Tom KQT
1

Share this post


Link to post
Share on other sites
You should base it on how far the target is. Because with a real gun anyone can shoot some thing when it's close. Eg the game Americas army must do something like your doing and I cant shoot anything in that game and that sux
1

Share this post


Link to post
Share on other sites

@ankhd: That's true, the player should be able to have better accuracy especially if the target is very close.

 

I'm not sure exactly what is the most efficient way to calculate the accuracy based on the weapon diversion angle and the distance, however I have done the calculation according to the weapon diversion angle and then increased the accuracy if the target is close enough.

0

Share this post


Link to post
Share on other sites

One thing that I think I should take care of is the bullet speed, in real life the bullet will arrive based on the speed and the distance.

So, I'm trying to find a way to delay the bullet arrival time for certain amount of time in milliseconds (depends on how far is the target).

 

The following should do the trick but definitely it will not only delay the bullet arrival but it will delay rendering as well:

while(...)
{
    // Delay until the bullet arrive (based on the bullet speed and the distance)
}

 

Maybe I can create a thread for shooting and do the above code in that thread then use a callback method to get the shooting result?

 

I need suggestion on what is the best way to do it without affecting the rendering, BTW I'm using a single method that I call for shooting and it should get me the shooting results every time I call it.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0