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

Force to apply after a deceleration to keep velocity constant

7 posts in this topic

Here is the problem:

 

I have a spaceship flying into space (3D world), so no gravity, no frictions etc, with a certain velocity and direction (heading).

The spaceship changes heading, the velocity direction clearly remain the same, then i apply a force of X Netwon in the opposite direction of the velocity. Now i want to apply a force in the heading direction so that it counterbalance the deceleration due to the previous force.. meaning that the velocity length vector has to be constant (but clearly the direction won't be).

It "should" be simple but for the life of me i can't get the amount of Netwon i have to give.

Edited by Smjert
0

Share this post


Link to post
Share on other sites

I think what you need to make sure is that the total force applied is perpendicular to the velocity. From that, all you need to do is compute the projection of the heading direction onto the velocity direction and scale the force applied in the heading direction so its projection is X Newton (with the appropriate sign).

 

EDIT: The answer should be something like X/cos(velocity,heading) Newton.

Edited by Álvaro
0

Share this post


Link to post
Share on other sites

I think what you need to make sure is that the total force applied is perpendicular to the velocity. From that, all you need to do is compute the projection of the heading direction onto the velocity direction and scale the force applied in the heading direction so its projection is X Newton (with the appropriate sign).

 

EDIT: The answer should be something like X/cos(velocity,heading) Newton.

So let me write this in Unity (C#) code and see if i understood it right (just testing there):

Vector3 currentVelocityDir = gameObject.rigidbody.velocity.normalized;
Vector3 currentHeadingDir = transform.forward; // This is kept up to date by Unity
float objMass = 10;
gameObject.rigidbody.AddForce(objMass * (-currentVelocityDir)); // Force to decelerate at 1 m/s^2

float cosAngle = Mathf.Cos(Vector3.Angle(currentVelocityDir, currentHeadingDir));

gameObject.rigidbody.AddForce((objMass / cosAngle) * transform.forward);

So this should be right? Because i'm not getting the correct result (the obj accelerates then suddenly lose a lot of speed, then accelerates again etc).

 

EDIT: Maybe i should add a bit more information, basicly i'm trying to simulate some assit engines that helps the spaceship to bank like an airplane but in space, but this engines have limited power. So the idea is that until the velocity direction doesn't correspond to the heading (or basicly the difference is less than some error value) i simulate an engine that decelerate on the opposite direction of the velocity and the main engines accelerating back to have constant speed, in the spaceship heading direction. Evochron uses this idea for instance (but i'm not sure about the method).

Edited by Smjert
0

Share this post


Link to post
Share on other sites

Computing the cosine of the angle is wasteful, since the angle is probably obtained as the arccosine of a dot product:

 

cos(angle(a,b)) = dot(a,b)/sqrt(dot(a,a)*dot(b,b))

 

If your vectors are both normalized (it's not entirely clear from your code that the heading is normalized), it's simply dot(a,b).

 

Plug in some values and see what the intermediate computations do. Is the total force perpendicular to the velocity?

1

Share this post


Link to post
Share on other sites

Yes transform.forward is normalized.

I retried to write it with the dot product Vector3.Dot(currentVelocityDir, transform.forward); and using that value to divide the X Netwons and.. it worked!

Or at least this is what it looks like even if, and i think this is due to rounding errors etc, i have a 0.001 increase of speed every second.

The dot between the velocity and the total force is not always 0 (for instance 7.723626E-08), but still a very small value and that's why there's that increase in speed i suppose.

And to keep velocity really constant i have to set it manually if > then expected one.
 

Edited by Smjert
0

Share this post


Link to post
Share on other sites
Even if the vector is perfectly perpendicular, the integrator you are using might end up increasing the speed. For instance, if you use the very basic Euler integration scheme, you would compute

new_velocity = old_velocity + dt * acceleration

In that case the new speed would be sqrt(old_speed^2 + dt^2*length_of_acceleration^2), which is systematically larger than old_speed.
0

Share this post


Link to post
Share on other sites

I was thinking out loud hehe, but thank you for your help.

Now i'm left with calculating the correct amount of deceleration needed for a particular turn, but that should be easy with circular motion equations.

0

Share this post


Link to post
Share on other sites

Ok unfortunately the method i use is not the correct one.

I mean the idea of slowing down the current velocity and then give thrust with the main engines in the heading direction doesn't make the velocity turn beyond a certain point and it will never make the velocity vector near enough to the heading.

What i should'have though earlier is: what is the "best" force that drags the velocity vector "near" the heading (especially since in the end i want a circular motion)? The centripetal force! I simulate one using the right local vector (because i'm currently dealing only with right turns tongue.png).

Now the problem though is to calculate the component of that force vector that acts as a deceleration for the current velocity.

What i thought is to obtain the magnitude of that deceleration vector doing dot(-velocityDir, forceVector.normalized) and then multiplying it to the magnitude of forceVector.

Then as earlier i do dot(velocityDir, headingDir) and then use it to divide the previous calculated magnitude and then use the result for the force with heading direction.

It kinda works, but the speed grows a bit too fast (like 10mm/s) so i think there's something wrong.

I've checked that the dot product between the resultant force and the heading direction is always around 0.

Also probably this doesn't support the case where the angle between the velocityDir and the centripetal force applied is > 180, where i have probably to flip some signs or the like..

Edited by Smjert
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