Jump to content


Photo

Rigid body physics help using GML


  • Please log in to reply
19 replies to this topic

#1 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 01 September 2012 - 11:19 AM

Hi, I was messing around in this forum and I found a topic talking about rigidbodies with gml, but I didn't understand, what all this is about, so please if you are expert in GML? please help me.
Thanks in advance
  • 0

#2 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 01 September 2012 - 02:59 PM

What have you tried? What has become the problem. And don't say "everything".

Currently this doesn't qualify for the Advanced GML Discussion forum.
  • 0

#3 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 01 September 2012 - 05:53 PM

I tried understanding collisions between two rigid bodies, using vectors and collisions points, but I dont understand, explain me please.
  • 0

#4 fantastichumore

fantastichumore

    GMC Member

  • GMC Member
  • 117 posts
  • Version:GM8

Posted 01 September 2012 - 08:09 PM

I tried understanding collisions between two rigid bodies, using vectors and collisions points, but I dont understand, explain me please.


I would say you should take a look at the "Extrem Physics dll", Are you good with gml? or do you work with the d&d functions?

Edited by fantastichumore, 01 September 2012 - 08:10 PM.

  • 0

#5 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 01 September 2012 - 08:52 PM

I'm good at gml, and I'm trying to figure this out using only gml, and before you give any code, please explain me the rigidbodies dynamics and how they works, it will highly appreciated.
Thanks in advance ;)
  • 0

#6 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 02 September 2012 - 10:20 AM

Here is a rigid body collision simulation written in Java. The math is explained below the applet.

You are going to need to understand vector math already, or at least the notations of the vector operations and how to write the vector math in x,y,z components, and use some scripts for those operations if you can't write them yourself.

You'll also need to understand what a surface normal means and how to detect it in the point of collision (as well as that point itself).

If you don't, you will not be able to figure this out yourself using only gml, and no one is going to write all the codes for you, either (as a rule of thumb you should minimize the amount of code that you don't understand in your projects, anyway). The theory of rigid body physics is built upon the framework of higher level math (such as vectors), so explaining its principles from the foundations of the math used would take months of work.
  • 0

#7 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 02 September 2012 - 01:03 PM

ok, do you have any idea how to detect collision between 2 bodies, and where is the point of collision(x,y)?
  • 0

#8 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 02 September 2012 - 02:07 PM

If your colliding bodies are polygons, you could check for each polygon if their vertices are inside the other bodies. If any vertex is, then there is a collision, and this vertex is the point of collision.

That is also covered in the link.
  • 0

#9 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 02 September 2012 - 03:04 PM

I'm using blocks, is there any function that could detect collisions?
  • 0

#10 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 02 September 2012 - 03:06 PM

No. You will have to come up with one of your own.
  • 0

#11 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 02 September 2012 - 03:12 PM

do you have any information that can help me in that, and a little information about me I'm in the first grade(High school)
  • 0

#12 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 02 September 2012 - 03:35 PM

You can find the vertice's closest points on the lines going through the principal axes of the rectangle, then test whether both the distances to those are below the width and height of the rectangle (if yes, the vertex is inside the rectangle).

You can also google point inside rotated rectangle.
  • 0

#13 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 02 September 2012 - 04:26 PM

So it will be like that:
pointx = (box1.x+box2.x)/2 //collision point x
pointy = (box1.y+box2.y)/2 //collision point y
if ((pointx) && (pointy))){
show_message("there is a collision")//meaning there is a collision
}
my code is right, right?
  • 0

#14 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 02 September 2012 - 05:54 PM

my code is right, right?

No..

The code goes to show that you are not going to be able to code a physics engine. You'll first have to learn the basics of programming, sorry.

For example, pointx is a coordinate (a double), not a truth value.
  • 0

#15 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 02 September 2012 - 06:17 PM

hey I'm good at gml, why should I learn, and if I'm wrong just explain me.
  • 0

#16 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 03 September 2012 - 02:41 PM

Please, help me, just explain me
  • 0

#17 SapperEngineer

SapperEngineer

    GMC Member

  • GMC Member
  • 110 posts
  • Version:Mac

Posted 03 September 2012 - 03:09 PM

That code shows that you don't know what you are doing.

You are doing an if statement on numbers (they are called doubles because that's what game maker uses.).

The if will never return true, because numbers can't be true. (Unless they are both 1.. but that's very unlikely)

I think Tepi's right, maybe you should brush up on GML before you try to write a physics engine.
  • 0

#18 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 03 September 2012 - 03:14 PM

(pointx, pointy) is a point between the two boxes.

In GML, as in many other programming languages, the structure of an if-statement is the following: if (<condition>) <statement>;. The condition has to evaluate to values false or true (logically). Truth values like this can be derived from conditions constructed by comparisons (some value) C (other value), where C represents '==' (or '='), '>', '<', '>=', or '<='. Conditions can be connected by logical connectives such as '&&' (or 'and'), or '||' (or 'or'). In many cases, you can even interpret the if-statement in natural language. A condition is logical only if it evaluates to true or false.

Now in your code you use "(pointx) && (pointy)" as a condition, but pointx and pointy are not conditions, since they evaluate to the coordinates of the point between the boxes, which is never (or, very rarely) false or true. If the point (pointx,pointy) happened to be (1.23, -7.6), then your if-statement would read "if 1.23 and -7.6, then do something", which doesn't sound very logical.

EDIT: Looks like SapperEngineer was faster than me.

Edited by Tepi, 03 September 2012 - 03:15 PM.

  • 0

#19 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 03 September 2012 - 06:41 PM

ah, I got the idea now, but do you have any idea or code snippet?
  • 0

#20 cj sniper 98

cj sniper 98

    GMC Member

  • New Member
  • 65 posts
  • Version:GM8

Posted 18 September 2012 - 07:50 AM

ok, what about this code :
if object1.x>=object2.x && object1.x <= object2.x+object2.sprite_width && object1.y = object2.y {
return true
}else if object1.x<=object2.x && object1.x >= object2.x-object2.sprite_width && object1.y = object2.y {
return true
}else if object1.y>=object2.y && object1.y <= object2.y+object2.sprite_height && object1.x >= object2.x && object1.x<=object2.x+object2.sprite_width  {
return true
}else if object1.y<=object2.y && object1.y >= object2.y-object2.sprite_height && object1.x >= object2.x && object1.x<=object2.x+object2.sprite_width {
return true
}else if object1.y>=object2.y && object1.y <= object2.y+object2.sprite_height && object1.x <= object2.x && object1.x>=object2.x-object2.sprite_width  {
return true
}else if object1.y<=object2.y && object1.y >= object2.y-object2.sprite_height && object1.x <= object2.x && object1.x>=object2.x-object2.sprite_width {
return true
}else{
return false
}

Edited by cj sniper 98, 25 September 2012 - 07:24 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users