• 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
Lars-Kristian

Bug in Verlet integrated physics engine.

6 posts in this topic

Hi everyone.

I am working on a game that uses Verlet integrated physics, and it works pretty well.
I got 2 types of objects vertices and edges.

The problem is when 2 horizontal edges collide and one of them is static, the other one jumps pretty high.

[attachment=11585:path3961-6.png]

Is this a common problem? does anyone know how to fix it?
0

Share this post


Link to post
Share on other sites
Its not common, i think. one object jumps becouse it layering other object too deep inside, it hapens than object speed is very high and steps are big or its got pressure from other objects or it depends on collision and (if exist) constraint satisfaction routine or verlet system update frequency or colision not allways calculated or ...
I had some problems with it, but it was just too meny object pressure, so I build in limits of object speed and it solved to me the problem.
But yours , I dont know, must see verlet integration code first to find the bug...
1

Share this post


Link to post
Share on other sites
Thanks for a good reply

The game is a typical bridge builder game. And the problem is with the train.

I have managed to get the jumping down to 2-3px, but it still looks horrible.

[attachment=11605:test.png]
[size=3]The train has not yet been given a texture[/size][size=3]. [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]


[size=4]I think the problem is here[/size][/size]

v1 and v2 is the edge, and m is the colliding vertex.
[CODE]
private void CollidingE(Vertex m, Vertex v1, Vertex v2, Vector2 cv) //cv = Collision Vector
{
if (v1.active == false && v2.active == false)
{
m.pos += cv * fraction;
return;
}

float t;
if (Math.Abs(v1.pos.X - v2.pos.X) > Math.Abs(v1.pos.Y - v2.pos.Y))
{
t = (m.pos.X - cv.X - v1.pos.X) / (v2.pos.X - v1.pos.X);
}
else
{
t = (m.pos.Y - cv.Y - v1.pos.Y) / (v2.pos.Y - v1.pos.Y);
}
float lambda = 1.0f / (t * t + (1 - t) * (1 - t));


Vector2 v1pos = v1.pos;
Vector2 v2pos = v2.pos;
Vector2 mpos = m.pos;

if (m.active == true)
{
if (v1.active == true && v2.active == true)
{
v1pos -= cv * ((1 - t) * lambda / 2.0f) * fraction;
v2pos -= cv * (t * lambda / 2.0f) * fraction;
}
else if (v1.active == false && v2.active == true)
{
v2pos -= cv * (t * lambda) * fraction;
}
else if (v1.active == true && v2.active == false)
{
v1pos -= cv * ((1 - t) * lambda) * fraction;
}
mpos += cv * fraction;
}
else
{
if (v1.active == true && v2.active == true)
{
v1pos -= cv * ((1 - t) * lambda) * fraction;
v2pos -= cv * (t * lambda) * fraction;
}
else if (v1.active == false && v2.active == true)
{
v2pos -= cv * (t * lambda * 2) * fraction;
}
else if (v1.active == true && v2.active == false)
{
v1pos -= cv * ((1 - t) * lambda * 2) * fraction;
}
}
v1.pos = v1pos;
v2.pos = v2pos;
m.pos = mpos;
}
[/CODE]


Or here
[CODE]
private void UpdateVertices(List<Vertex> list)
{
Vector2 tmp;
foreach (Vertex v in list)
{
Vector2 pos = v.pos;
Vector2 oldpos = v.oldpos;
Vector2 deltapos = v.deltapos;
if (v.type == Vertex.NORMAL)
{
deltapos.X = 0;
deltapos.Y = v.mass;
deltapos -= (pos - oldpos) * 0.0001f;//0.0001f * (pos - oldpos);
tmp = pos;
pos += pos - oldpos + deltapos;
oldpos = tmp;
}
else if (v.type == Vertex.TRAIN)
{
deltapos.X = 0;
deltapos.Y = v.mass;
deltapos -= 0.05f * (pos - oldpos);
tmp = pos;
pos += pos - oldpos + deltapos;
oldpos = tmp;
}
else
{
pos = oldpos;
}
v.pos = pos;
v.oldpos = oldpos;
v.deltapos = deltapos;
}
}
[/CODE]
0

Share this post


Link to post
Share on other sites
I have looked at your code, and find some strange things...

cv * fraction - is this a friction or that? If so its applies to all direction independantly on surfase orentation. Must be orented to surface...

You sometimes push v1 and v2, but dont push m, I downt know these parameters belongs to train or bridge, are theey skick or not

After such code you push v1 v2 /2 , bus push m /1[CODE]
{
v1pos -= cv * ((1 - t) * lambda / 2.0f) * fraction;
v2pos -= cv * (t * lambda / 2.0f) * fraction;
}
[/CODE]
Must be m/2 too:
[CODE]mpos += cv * fraction/2,0f;[/CODE]

If deltapos is for inertia, your update function looks weard for me:
object mass must figure in collision routine not in object move
I simplefied your coude and mass is gravity?gravity for all ojects must be the same :)
[CODE]
tmp = pos;
pos += (pos - oldpos)* 0.9999f+(0,v.mass);
oldpos = tmp;
[/CODE]
1

Share this post


Link to post
Share on other sites
I understand that not everything makes sense. :P
The fraction thing is a variable between 0.5-1.0, it helps making everything more stable.
If something collides, instead of moving both object all the away from each other, they are only moved by a fraction. like a dampening effect.

m is a vertex, v1 and v2 is an edge.
If a vertex is active it can move, but not if its not active.

I agree with that mass thing.
Are you saying that if 2 objects collide, the object with the least mass moves the most?
0

Share this post


Link to post
Share on other sites
hmm wrote an answer but it disapeard .
ok I will answer again [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
I think maybe your problem is in two places , try to rewrite these places with code below
maybe this helps...

[CODE]

if (v1.active == true && v2.active == true)
{
v1pos -= cv * ((1 - t) * lambda / 2.0f) * fraction; // (1-t)/2
v2pos -= cv * (t * lambda / 2.0f) * fraction; // t/2 ( t+(1-t))/2=1/2 half energy for edge
}
else if (v1.active == false && v2.active == true)
{
v2pos -= cv * (t * lambda/2.0f) * fraction; //half energy for edge
}
else if (v1.active == true && v2.active == false)
{
v1pos -= cv * ((1 - t) * lambda/2.0f) * fraction; //half energy
}
mpos += cv * fraction/2.0f; // if half energy for edge so must leav half energy to m
[/CODE]

About mass, ofcouse if mass different , collision will effect diferently for that objects


[CODE]
//redistribute energy to objects with different mass
float c=1/(obj1.invmass+obj2.invmass);
obj1.vec -= obj1.invmass*c/2*collision_vector;
obj2.vec += obj1.invmass*c/2*collision_vector;
//invmas=1/mass;
[/CODE] Edited by serumas
1

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