Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Problem with collision; Can't figure out where the problem is
Topic Started: Mar 12 2009, 01:00 AM (436 Views)
hepolite
Advanced Member
[ *  *  * ]

I'm havng a little problem with my collision code, and I can't find out where the error is. This code works for some unknown reason in another game I have, but here, it doesn't work... It always detects a collision, even when I'm belove the solid things.

I did my best, but I failed, so I hope someone here can help me out.
Here's the code I'm using:
Code:
 
var vector,xx,yy,zz,z2;
xx = x;
yy = y;
zz = z;

x += (velocity*1)*cos(pi/180*(-roty+90));
y += (velocity*1)*sin(pi/180*(-roty+90));
z += zspeed;
zspeed -= zgravity;

if (on_ground == 1)
{
// Walk down slopes
z -= hip_height*0.25;
}
else
{

}

external_call(global.u3d_set_object_solidity,collision,1,0,0);
// Using room 5 to avoid drawing the collision shapes
vector = AttemptMoveToPosition(-1, all, xx, yy, zz + (height*.5)-hip_height, x, y, z + (height*.5)-hip_height, roty, rotx, rotz, width, length, height, 5);
external_call(global.u3d_set_object_solidity,collision,1,1,0);

x = GetVector(vector,1);
y = GetVector(vector,2);
z2 = GetVector(vector,3) - (height*.5)+hip_height;

ReleaseVector(vector);

// I believe something is wrong here...
if (z != z2)
{
if (zspeed <= 0)
{on_ground = 1;}
zspeed = 0;
}
else
{
on_ground = 0;
}

z = z2;
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
hepolite
Mar 12 2009, 01:00 AM
Code:
 
external_call(global.u3d_set_object_solidity,collision,1,0,0);
// Using room 5 to avoid drawing the collision shapes
vector = AttemptMoveToPosition
(
-1, all,
xx, yy, zz + (height*.5)-hip_height,
x, y, z + (height*.5)-hip_height,
roty, rotx, rotz,
width, length, height,
5
);
external_call(global.u3d_set_object_solidity,collision,1,1,0);
I guess you're setting the collision shape to non-solid before collision checking, to test if you can disable collisions with it? If you're still getting collisions, there must be other objects in room 5 that are still solid. (Btw, make sure that "collision" is not an instance id, but an u3d index).

Apart from that, any particular reason why you pass roty, rotx, rotz in that order to AttemptMoveToPosition(...)?
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
hepolite
Advanced Member
[ *  *  * ]
Currenly, I only have the player and a level in the room. I tried to make everything unsolid, and it still detected a collision...
After messing a litte bit around, it seems to sort of work, but if the player goes under the level, the whole thing is bugged up again.

I removed he rotx/y/z, it seems like i didn't do too much. I had it there because the length and width of the model is not the same.

This is how I load the collision box and the model (I do the same for the level, except I have another collision model there):
Code:
 
file = <modelpath>;
password = <password>;
LoadMesh();
SmoothNormals(180);
SetModelMaterial(0, 255, 255, 255, 255);
SetObjectSolidity(0, 0);

// Create collision box
file = "mod\collisionbox.an8";
collision = external_call(global.u3d_load_mesh, file, password); // Load the file
external_call(global.u3d_set_object_solidity,collision, 1, 1, 0); // Set the model solid
external_call(global.u3d_set_object_room, 1, collision, 5); // Move the model to the collision room

Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
hepolite
Mar 12 2009, 04:30 PM
(I do the same for the level, except I have another collision model there)
So you have 2 GM objects, each with a collision shape belonging to room 5? If you execute the code I quoted in my previous post for each collision shape (that is, twice per step), then the one for which it is executed first will be detected during the second execution, since it's set back to solid at the end of that code.

If that's not it, make room 5 visible and check exactly what object the player is colliding with.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
hepolite
Advanced Member
[ *  *  * ]
I set the cllision model unsolid, otherwise the player character would collide with this model instead.

The level is solid all the time, I don't change it's solidity.

I tried to make room 5 visible, but I didn't see what was wrong. The I did another test, I tried to check for collisions with room 10, even if there's nothing there. Collisions were detected.

I know I can't provide enought information, so I just have to post the source code. I hope the problem can be solved...
(I doubt that people would steal a game with just a camera, level and a player..)
Attached to this post:
Attachments: Start.gmk (55.89 KB)
Edited by hepolite, Mar 12 2009, 10:11 PM.
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
hepolite
Mar 12 2009, 09:56 PM
I did another test, I tried to check for collisions with room 10, even if there's nothing there. Collisions were detected.
That's definitely not normal.

Maybe it's because you're using an outdated extension (2.1 Beta), so upgrade to the latest version and see if that helps.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
hepolite
Advanced Member
[ *  *  * ]
I downloaded the final GEX file, and it didn't help much. I tried to make a new collision code, but I ran into a problem there too. The player seems to stop in mid-air for no reason, then continue to fall after a few seconds.

Code:
 
var vector, xx, yy, zz, z2;

xx = x;
yy = y;
zz = z;

x += (velocity*1)*cos(pi/180*(-roty+90));
y += (velocity*1)*sin(pi/180*(-roty+90));
z += zspeed;
zspeed -= zgravity;

vector = AttemptMoveToPosition(-1, all, xx, yy, zz + (height*.5)-hip_height, x, y, z + (height*.5)-hip_height, 0, 0, 0, width, length, height, 0);

x = GetVector(vector, 1);
y = GetVector(vector, 2);
z2 = GetVector(vector, 3) - (height*.5)+hip_height;

ReleaseVector(vector);

if (z != z2)
{
zspeed = 0;
on_ground = 1;
}
else
{
on_ground = 0;
}

z = z2;

It does detect collisions, but also when there's no solid models close up.

EDIT:
It appears to be a precision glitch with "if (z != z2)". I added ceil around both of them, and no more collision were detected in mid-air. But it's still some weird things going around. The player bounces when he stands still on the ground, and it looks really bad.
Edited by hepolite, Mar 14 2009, 02:16 PM.
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
hepolite
Mar 14 2009, 01:58 PM
It appears to be a precision glitch with "if (z != z2)". I added ceil around both of them
That's exactly what's causing the bouncing. Try the following instead:
Code:
 
if (abs(z - z2) > .001)
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply