Jumping screws up collision

Posted By: Valdsator

Jumping screws up collision - 01/10/12 23:08

I have a simple problem in my game at the moment.

When there's a doorway or a vent in my game, jumping at the wall above it results in the player moving through the wall once he has landed. I want to prevent this from happening. I made the player automatically crouch if this happened, but it gets in the way of other things, and is a rather rough fix.


NOTE: This image isn't completely accurate. The open space below has to be a bit bigger. What's shown above wouldn't actually result in the player moving through the wall.

Anything I can do to prevent this?
Posted By: msmith2468

Re: Jumping screws up collision - 01/11/12 02:16

well how do you have it set up? are you using c_move? do you have USE_BOX set with a FAT or NARROW haul? I guess i don't really have enough information to help you. It appears from your drawing that the majority of you players body is going through a wall which means that your collisions box must be smaller then the player. did you use c_updatehull?

Here is a link to Game Studios Collision Engine details. http://www.conitec.net/beta/collision.htm
Posted By: Valdsator

Re: Jumping screws up collision - 01/11/12 03:39

Yes, I'm using c_move. I have the eflags FAT and NARROW set so I can change the collision box. Increasing the width and length of it doesn't seem to help, since once the player gets inside a block, nothing stops him. Collision with that block doesn't work until he gets out himself. No, I did not use c_updatehull, I manually set the max_x and min_x.

The red oval in my drawing is representing the collision ellipsoid of the player, and I have it set to be as big as the player model, except for the bottom, which is a bit shorter than the actual model. Making it the proper length doesn't fix the issue, though.

max_x is 8, 8, 45
min_x is -8, 8, -20

I think one thing causing the issue is the fact that the collision box is an ellipsoid. Since there's an opening, some of the ellipsoid is able to go through before colliding with the upper wall. Of course, this isn't the main reason, because I can do this without jumping, which simply results in the player getting slightly closer, and gliding horizontally getting all jittery.
Posted By: Carlos3DGS

Re: Jumping screws up collision - 01/11/12 21:46

a few things come to mind...

-Do you use c_move only for moving (forward,back,left,right), or do you also use c_move for the gravity?
-Do you use glide?
-How have you set max_x and min_x? Do you also use max/min_y and max/min_z?
-Have you tried using c_setminmax(me); instead of manually setting the collision hull size?
-If you character can also rotates... Do you just change the angles directly, or do you use c_rotate?

Not much more people can do for you though, if you don't post your movement code...
Posted By: Valdsator

Re: Jumping screws up collision - 01/11/12 23:37

I use c_move for gravity, yes.
I use GLIDE on this c_move.
I set max_x and min_x via vec_set.
Code:
vec_set(my.max_x,vector(8,8,45));
vec_set(my.min_x,vector(-8,-8,-20));


The reason for the bottom being only 20, while the top is 45 is because I use a c_trace to check for the floor, allowing the player to walk up stairs and such. Setting the -20 to -45 doesn't solve the issue, and since the c_trace is shooting downward, I don't think that's causing the problem (I think I'll test this just in case).

I tried c_setminmax(me); just now, but that didn't solve it. That's also a bit inconvenient due to the reason stated above.
The character rotates using my.pan -= mickey.x; I just tried using c_rotate, but that didn't change anything.
Posted By: Carlos3DGS

Re: Jumping screws up collision - 01/12/12 02:19

To my understanding it seems you are doing things right (at least in those cases that came to mind when I read your problem).

A few other thigs came to mind:
-Do you ever modify the x/y/z or pan/tilt/roll directly in another part of your code? (outside of the c_move/c_rotate functions)
-Are you animating your model? If so, are you using the POLYGON flag for the entity? Try to see what happens withought POLYGON.

On a different aproach to your problem also consider the following:
-the problem might not be in your code, it might be in the model you are using.
-Open the model in med. Are the feet at the axsis origin? Or is the waist around the axsis origin?
-Open your model in med, Object menu -> Transform Global -> Center Model, then save the model and test it again in your script (make a backup copy of the model first).
-include "default.c" in your main script. Run the code and press "F11" two times. Repeat the process that is giving you problems while you observe how the collision box behaves.

Searching for other possible causes... The problem might not be in your script nor in the character model, mabe it is the object you are colliding with.
-Is the object you are colliding with a WED block or another model?
-If it is a model... Is the origin at the center of the model? (you can check this in MED)
-Try to use c_setminmax(object); for the object you are colliding with.
-include default.c in your main script, run the game and press F11 twice, but this time look at the collision box of the object you are colliding with.
Posted By: 3run

Re: Jumping screws up collision - 01/12/12 10:17

How fast your player moves?
Posted By: Valdsator

Re: Jumping screws up collision - 01/13/12 02:56

30 * time_step is the top speed, but I don't think that's the problem.

I just made a new project with the same level and player model, same horizontal movement code, but a simple jump system, and now the issue is gone. Also, when the player glides against the vent, the reaction isn't so jittery. I have other code in the player of course, so I really don't know what's causing this problem. I'm going to do more tests and see if I can fix it.

EDIT: Ok, I replaced my old vertical movement code with the simple jump code and the issue has disappeared. I guess I'll go and try changing certain lines to see what specific code is causing the problem, and see if I can change it.

EDIT 2: Alright, so apparently it's the code that allows the player to go up slopes and stairs easily. More specifically, it's the code that snaps the player to the ground/slope (using my.z = ) so it's a smooth climb up or down. I guess I just need to find a different way to accomplish this.

Thanks to everyone who helped! laugh
Posted By: Carlos3DGS

Re: Jumping screws up collision - 01/13/12 13:56

Originally Posted By: Carlos3DGS
-Do you ever modify the x/y/z or pan/tilt/roll directly in another part of your code? (outside of the c_move/c_rotate functions)


Ok a possible solution to your problem that will allow you to keep your code that calculates climbing up/down slopes smoothly...

Take the calculations from your "my.z = blablabla;" but instead of assigning it directly to my.z do something like this:

z_difference = my.z-(blablabla);
c_move(me,nullvector,vector(0,0,-z_difference),FLAGS);

That should give the same result you had before but it now considers collisions.
hope this helped!
Posted By: Valdsator

Re: Jumping screws up collision - 01/14/12 01:15

Hah, you're a genius. Never would have thought of that. Thanks! grin
Posted By: Carlos3DGS

Re: Jumping screws up collision - 01/14/12 02:23

No problem, hope you got it working.

Not a genius, just a different aproach. Whenever I get stuck i post on these forums to see what solutions can come from diferent points of view.

"If you give the same problem to 20 people you will end up with 10 different ways to solve it... If you give a problem to 20 creative people, each will give you 10 different ways to solve it, resulting in 200 unique solutions."
And I find programmers to be very creative people, especially those involved in game programming.

That actually sounds pretty good... It might turn into my new forum signature!
© 2024 lite-C Forums