Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Player collision on bone animated object?

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Oct 2010 19:58
Hi guys!


So how should I be going about with collision on a bone animated object? I'm aiming for something like this:

http://www.youtube.com/watch?v=47PPDIjJun8

(video is uncut, because stupid Windows Move Maker won't start anymore...)

The player sticks to the fish's tail, no matter where he goes. I'd like to achieve that for my current project. Correct rotation of the player is unnecessary, because Mega Mash Mothers is a 2.5D game.

I have been brain storming on what the most effective way to do this would be, and thought it may be possible to get the position of the vertices currently forming the face that the player is standing on, compare that data with the last frame of the object, and then do calculations to reposition the player.

This is all fine and good, but I really don't know how to tackle it when the vertices deform the face... What happens to the player when the face stretches or shrinks, or even twists into weird shapes?


The other method I thought of, but I don't like it much because it's less dynamic, is I reposition the player according to the "skeleton" of the object, so instead of checking vertices, I check limbs. However, this can lead to tons of problems such as when two limbs share the same face.


Any suggestions, help, or even code are greatly appreciated!

TheComet

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Oct 2010 14:51
I have a feeling that using enhanced animations you have the option to update the object boundaries but I don't know whether that will translate across to say sparky's collision (or whatever you're using)...

Latch
20
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Oct 2010 00:09 Edited at: 22nd Oct 2010 22:47
I misunderstood your goals - what was here is not useful for this.

Enjoy your day.
Neotron
16
Years of Service
User Offline
Joined: 21st Jul 2010
Location: I am in an underworld , making a E.Army
Posted: 21st Oct 2010 19:49
i think you are saying that the platform(fish tail) is moving but the player doesn't move according to the fish movements right?

if so then i might have a theory for you.

first make limb at the edge of the fish's tail calculate its offset and add it to the player's position and position the player on the new position.and if this gets working then do the next thing.

second set a variable that turn on when the player is moved by the player or any other force and calculate the collision and other(gravity).

third if all above becomes successful and the variable move is "on" then add the new position to the limb position, this should reposition the character to the platform.

If this works then i have solved my first post of the career.(don't know what i said but this is the first time i have ever helped anyone).

thnx for listenning.

ALLAH IS THE GREATEST
May he forgive me
Neotron
16
Years of Service
User Offline
Joined: 21st Jul 2010
Location: I am in an underworld , making a E.Army
Posted: 21st Oct 2010 20:06
And if more bones share one vertex then you might need to fix your model .One bone per vertex also has some good animation.

If you can't do it then ummm...then do this.Make a move variable/jump/fight/slip.If the variables are off then move the fish a little bit and store the position values xz only of the character calculate(sparky IS INVOLVED) the collision between fish and the character. ALRIGHT THIS DOESN"T WORK A BIT.
OK now let's see.
1. Calculate the character and the fish collision and then use the SC_GETFACEHIT command and get the polygon of the fish and after that get the nearest vertex of that polygon,get the position of the vertex and then subtract and add the vertex position into the charater position.

hope this helps sorry for the frustation.

ALLAH IS THE GREATEST
May he forgive me
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 21st Oct 2010 20:40
An ever-changing collision shape is generally a tricky issue to handle.

For starters, it's probably not a good idea to have such a thing as an animation - it's an important piece of level geometry, so I'd suggest handling the 'animation' manually, adjusting vertices yourself or using a collection of object segments which you can scale and rotate. This way you know exactly where each surface is at any given moment in time, since you're handling the timing yourself.

As for how to actually implement the collision it depends on what collision system you're using.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st Oct 2010 23:21
It depends if you're using sparky's collision or what.

If you know the point that the player is at, and the point of the two vertices of the surface the player is standing on, then it wouldn't be too hard to find the point the player would be standing on after the vertices are transformed.


SO if you can find those two vertices positions this frame and the next frame, then you're good ta go!

I only have 25 mins but I'll try to code up a working example of what I'm talking about in that time...

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Oct 2010 23:25 Edited at: 21st Oct 2010 23:28
Quote: "1. Calculate the character and the fish collision and then use the SC_GETFACEHIT command and get the polygon of the fish and after that get the nearest vertex of that polygon,get the position of the vertex and then subtract and add the vertex position into the charater position."


Something along those lines is what I am looking for. I remember seeing the SC_GetFaceHit() command, but never really used it. This could help out a lot.

Quote: "For starters, it's probably not a good idea to have such a thing as an animation - it's an important piece of level geometry, so I'd suggest handling the 'animation' manually, adjusting vertices yourself or using a collection of object segments which you can scale and rotate."


I considered the option to control it manually, but that is going to get really complicated according to my plans. If the collision system only requires to know where each vertex and surface is at any given time, then this can be acquired with using the vertexdata commands.

Quote: "As for how to actually implement the collision it depends on what collision system you're using."


I'm not sure what you are asking, but if it helps, I can post the structure of the collision system:

-add force vectors to positions (gravity, hit force, movement etc.)
-check collision with level objects
-add collision vectors to positions (prevent player from going through walls)
-update player object with positions

So if I were to implement the animated collision into the current system, it would be after the forces, and before the collision checks.

-store old position values
-add force vectors to positions (gravity, hit force, movement etc.)
-use old+new vertex positions of bone animated object, and old+new player positions to calculate an offset
-add offset to positions
-check collision with level objects
-add collision vectors to positions (prevent player from going through walls)
-update player object with positions

OK, I'll try and code something now and see if it works

Quote: "It depends if you're using sparky's collision or what."


Yep, I'm using sparky's

Quote: "If you know the point that the player is at, and the point of the two vertices of the surface the player is standing on, then it wouldn't be too hard to find the point the player would be standing on after the vertices are transformed."


Quote: "SO if you can find those two vertices positions this frame and the next frame, then you're good ta go!"


Getting those positions required for the calculation should be the easy part, it's the calculations for the transformation that are screwing me...

Quote: "I only have 25 mins but I'll try to code up a working example of what I'm talking about in that time..."


Awesome, thanks a lot in advance!

TheComet

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st Oct 2010 23:47
awwh, can't finish it in time. Started doing it a hard way then figured out an easy way. I'll describe how:



Say you have a line from point A to point B, that can be described parametrically:

x=(Bx-Ax)*t+Ax
y=(By-Ay)*t+Ay

Then you can solve for T. Since "down" is just -1 on the y axis, its best to solve for t in terms of the x coordinates:
t=(x-Ax)/(Bx-Ax)

x here can be the position of the player on the x axis, nothing complicated.

So, now we can describe another line from C to D, which can be described parametrically as:
x=(Dx-Cx)*t+Cx
y=(Dy-Cy)*t+Cy

Plug in T, and x and y will be the transformed coordinates.
t=(x-Ax)/(Bx-Ax)
x'=(Dx-Cx)*t+Cx
y'=(Dy-Cy)*t+Cy

(in case I'm not clear, Ax, Bx, Cy, whatev, are all single variables, not A*x)

So, if your character is supposed to be positioned S units above the ground, originally has the x-position "x", is standing on a line from A to B, and after the transformation is standing on a line from C to D:

t=(x-Ax)/(Bx-Ax)
x'=(Dx-Cx)*t+Cx
y'=(Dy-Cy)*t+Cy+S

What my code was going to do is do this transformation every time the user clicked and moved either point A or B (so C or D would be the new position, and A and B would be the positions last frame), draw the line from A to B, and position a box at x', y'.

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 22nd Oct 2010 06:38
Okay, here's a cooleo demo:


right click, left click, and press the arrow keys.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Oct 2010 10:24 Edited at: 22nd Oct 2010 10:26
That all sounds very complicated. I did moving platforms using sparky's and just did this.

1.Check for collision (and that it is a platform using sc_getcollisionnormaly()
2.Check for movement/rotation from the collision object
3.Add the movement/rotation to your player object

...simple no?

EDITf course you'll need to handle animation of the 'platform' objects using seperate objects (if it's like the fish tail) not limbs but that's not so hard...

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Oct 2010 22:05
@ Neuro Fuzzy

Awesome demo, that's exactly what I'm aiming for! I'll just have to get it into 3D now, not only 2D. [Time passed] Well after some thinking and testing, I have gotten nowhere... In 3D you have 3 points, each connected to each other, so 3 lines. And the player is somewhere in between those lines, standing on the surface they create. How to calculate how much the player shifts when the face deforms?

[More time passed]

OK, I think I have come up with something. I figured the closer the player is to one of the corners of the face (one of the vertices), the more it is affected by it's movement. So it is possible to retrieve a number between 0 and 1, which indicates how much the player should move according to the vertex.

So given vertex positions A,B,C, I can set up the old positions of them, and the new positions : nAx, nAy, nAz, oAx, oAy, oAz, nBx, nBy etc...

Aaand, that's how far I've gotten for now. I'll be off and study a little more.

TheComet

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 22nd Oct 2010 23:38
I thought it was just teh 2d case that mattered?

Well... here's some code for the 3d case:


I'm really not sure how to get the coordinates for each vertex tho...

Using that function (in pseudo-code) would look something like this, I think:



I hope this helps

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Oct 2010 02:40
This is what I could code for now, what is wrong?



Or did I totally misunderstand you, Neuro Fuzzy?

@baxslash

Problem is that the object doesn't only move, it deforms... Otherwise your method would be the best to go for

TheComet

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 23rd Oct 2010 04:39
:\

I can't really tell what that's doing.

I would base your code around these functions:
either this for the 3d case:

(a point on the surface of a triangle being moved, as the triangle warps to another triangle)

or this:






the first function takes a point on the first triangle (defined by a1, a2, a3) and transforms it to a point on the second triangle (b1, b2, b3).

The second function takes a point on a line (defined by a1, a2) and transforms it to a point on another line (b1, b2).

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Oct 2010 13:00 Edited at: 23rd Oct 2010 13:04
Oh whoops, I'm terribly sorry, for some reason I didn't look at the post above my last one

Thank you so much for your efforts, that's exactly what I wanted!

This is the code:



Cheers!

TheComet

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 24th Oct 2010 22:31
Well, I'm a little stuck... I used SC_GetFaceHit() to return the face the player is currently standing on, and now I'm wondering how to find the vertices making up the face... Is it get indexdata()? That command only ever returns a 0, no matter what I do...

TheComet

Neotron
16
Years of Service
User Offline
Joined: 21st Jul 2010
Location: I am in an underworld , making a E.Army
Posted: 25th Oct 2010 12:23
i think one of the examples with a ninja has something about the vertices.

Cant make a code i have an Exam,after 3 weeks i suppose?

ALLAH IS THE GREATEST
May he forgive me
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Nov 2010 18:05
bumping this...


Does anyone know how I can get the vertex indexes from the face index?

TheComet

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 3rd Nov 2010 22:38
you might try firing off an e-mail to the guy that made sparky's collision.

Login to post a reply

Server time is: 2026-07-26 05:03:42
Your offset time is: 2026-07-26 05:03:42