• 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
KillaChaos0

Bullet Rotation

5 posts in this topic

I am using pyBox2D for my game. My problem is when the player shoots the bullet's angle never changes on the path (i.e I shoot a bullet into the air, its angle stays the same through out its life, whereas in real life if a bullet is fired into the air at its highest point it will do a "180" degree flip) How can achieve this effect?
0

Share this post


Link to post
Share on other sites
Quote:
Original post by KillaChaos0
I am using pyBox2D for my game. My problem is when the player shoots the bullet's angle never changes on the path (i.e I shoot a bullet into the air, its angle stays the same through out its life, whereas in real life if a bullet is fired into the air at its highest point it will do a "180" degree flip)


I don't think it will. If the bullet is fired straight up, once it loses enough speed it will fall wobling chaotically. If fired at a lower angle, it retains a ballistic trajectory and then the bullet's orientation follows the trajectory, as you would expect. There is a MythBusters episode about it.
0

Share this post


Link to post
Share on other sites
Presumably that depends on the bullet and what the weight distribution is like over the object.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by KillaChaos0
I am using pyBox2D for my game. My problem is when the player shoots the bullet's angle never changes on the path (i.e I shoot a bullet into the air, its angle stays the same through out its life, whereas in real life if a bullet is fired into the air at its highest point it will do a "180" degree flip)

How can achieve this effect?


if you have access to the bullet velocity, add gravity to it (bullet.velocity += gravity +* dt).

if you have access to forces acting on a bullet, add a gravity force to it (bullet.addForce(gravity * bullet.mass)).

If you have wind and air resistance, you can do something similar as well.
0

Share this post


Link to post
Share on other sites
You can use kinematic equations.

Assuming you have a initial launch velocity and an angle, then you can do something like this,

const float accel = -9.8 * 0.001f; //factor
const float initLaunchVelocity = 4.0f;
const float launchAngle = 90.0f; //degree
const float velocityMagnitudeInX = initLaunchVelocity * cos(launchAngle);
conat float velocityMagnitudeInY = initLaunchVelocity * sin(launchAngle);
const float dt = 1; [EDIT : dt should be the elapsed time, sorry ]
bullet.x += velocityMagnitudeInX * dt;
//Y = vt - 1/2at^2
bullet.y += velocityMagnitudeInY * dt - 1.0f/2.0.f * (accel) *(dt * dt );



as you see if the launchAngle is 90 degree then there will be no velocity in
the x direction because cosine of 90 degrees is 0. That means all the force goes
in the y-direction.

Also here :
 bullet.y += velocityMagnitudeInY * dt - 1.0f/2.0.f * (accel) *(dt * dt );


The "- 1.0f/2.0.f * (accel) *(dt * dt) " factor will eventuall get bigger than
velocityMagnitudeInY, then that means it will eventually decrease; which in
turns means that bullet.y will eventually decrease.

[Edited by - Concentrate on January 10, 2010 9:51:56 PM]
0

Share this post


Link to post
Share on other sites
Never heard of pyBox2D, but the following should hopefully apply regardless of what you're using.

Simply simulate the effects of gravity and perhaps air-resistance on your bullet, just as you would with any other object in a realistic simulation.
In addition to doing
position += velocity;
for the bullet each frame, also do:
velocity.y += GRAVITY;
// and
velocity *= AIR_RESISTANCE;
It's that easy!
Tweak both constants to suit your aplication.

E.g. Assuming you use 1.0 for one metre and your bullets travel at realistic speeds, GRAVITY (on earth) is about 9.8 which we divide by the number of game logic updates per second, since we apply it that many times. Assuming 50 updates per second, GRAVITY = 9.8 / 50 => 0.196

The AIR_RESISTANCE factor makes sure that the object doesn't exceed terminal velocity, or increase in speed forever.
It should be a number just a smidgen below 1.0, though the actual value again depends on the update rate (in a more complex way).
Say you want your speed to drop by 5% (i.e. 0.05) per second, and your update rate again is 50 updates per second.
AIR_RESISTANCE = (1 - 0.05) ^ (1 / 50) => 0.998974...

Your bullet angle is calculated from the arctan of it's x and y velocity, which iirc is: BulletAngle = atan2(velocity.y, velocity.x);

avaro is corrct though that if fired directly upwards then there is no particular way that it would turn to reorient itself towards the ground, and it will in fact flop all around for a moment, eventually settling into whatever orientation provides the least air-resistance, and depending on its angular momentum it may even result in spiraling downwards. However, from my understanding, there isn't any need to go into that much detail in your case.

Edit: While Concentrate has tried to make something useful out of kinematic equations, what he posted definitely isn't right. He has confused a fixed time step with elapsed time, and confused actual height with accumulated height, and as such what he posted has unfortunately not come out at all correct.
Even with the correct usage of the formula, the equation would describe a parabolic path of the projectile. However that formula is only correct for when air-resistance is negligible, and with bullets at high velocities, air-resistance is far from negligible. In fact it may even have more effect than gravity initially! A bullet fired off a cliff with the formula used correctly, would hit the ground far below at an impossible speed. Not to mention that you'd still have to differentiate the function in order to get the actual angle. Needless to say that it is not the right approach.

[Edited by - iMalc on January 9, 2010 5:29:24 PM]
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