Collision problems - demo to help clarify...

Posted By: Rad_Daddy

Collision problems - demo to help clarify... - 10/08/06 04:44

I have been working on a small hobby project in my spare time, and have put together a very small demo of what I want to accomplish with the movement script. It includes strafe movement, forewards and backwards movement, and a view box that moves the camera at a constant rate as a function of time. However, the collision is a little funky, and I would like a little help on the matter.

What I am trying to accomplish is, allowing the player to move freely inside the view_box, but stop the player as soon as it hits the box's bounds. Also, if the player stops all movement, I want the position relative to the box to be maintained, so for instance, if the player stops in the dead centerof the box, he should remain dead center until he/she moves again. My problems are as follows...

1. If the player stops moving, the back of the box slowly closes the distance, and the player goes outside of the box. This seems to be because collision is not applied unless one of the w,a,s,d buttons are pushed (c_move)

2. There seems to be an invisible box in the center of each terrain that, for some reason blocks the player from moving foreward. You can move around it, but it needs to go .

If anyone has any ideas on how to fix either of these problems, I would be very greatful. To help you in every way possible, I have put together this small demo, for you to look at. It is an eye-sore, but it gets the point across. All code is open-source, for easy review. The demo can be found here.

A few notes:

-Terrain tileing system is not implemented.
-View box is visible for testing purposes.
-Code is not commented, because I havent gotten around to it... sorry.

Thank you again, hope the demo + code/explination is enough to get my point across

Regards,
Raddaddy
Posted By: Slin

Re: Collision problems - demo to help clarify... - 10/08/06 10:55

You are moving the view box through adding to its y-position.
Because of this the view box donīt do any collisiondetection and moves through the player. Maybe, you could use "clamp" instead of your view box like this:

clamp(player.x,camera.x-500,camera.x+500);
clamp(player.y,camera.y-700,camera.y+700);

For me there is no Problem with those terrains.
Iīm using Version 6.50.2. Maybe it was a Problem with 6.40.5.

Hope this Helps
Posted By: Rad_Daddy

Re: Collision problems - demo to help clarify... - 10/08/06 14:38

I am using 6.40, did not know 6.5 was available... anyways, thank you for the tip about clamp, I will look into it further when I get some more free time.

Thanks again,
Raddaddy
Posted By: Rad_Daddy

Re: Collision problems - demo to help clarify... - 10/09/06 03:25

Sorry, after thinking things through for a few minutes, a few things come to mind. I tried out the clamp function you mentioned, and I have a few questions about how it would work...

1. How can I make the screen move at a constant rate? Would I have to move the terrain rather than the player?

2. If I were to use clamp, the camera could no longer be set at the view_box's coordinates, thus moving the camera wherever the player goes (camera.x = player.x, ect.) How Could I set the camera to look down without actually following the charaacter.

3. As far as clamp is concerned, is it resolution indipendent? I wouldnt want the movement bounds to mess up if the player chooses a different resolution other than my test resolution (1280x800).

Thanks again in advance,
Raddaddy
Posted By: Slin

Re: Collision problems - demo to help clarify... - 10/09/06 13:31

1. Change the cameras x/y position as you did with the view box:
function move_camera()
{
camera.tilt = 90; //turn the camera to the bottom
while(1)
{
camera.y += 1*time_step; //move the camera
wait(1);
}
}

2./3. Use vec_for_screen to get your screens frame:
action player
{
var screen_pos1[3]; //vector definition
var screen_pos2[3]; //vector definition
screen_pos1.z = camera.z-player.z;
screen_pos2.z = camera.z-player.z;
while(1)
{
//movement, ...

screen_pos1.x = 0; //upper left corner of the screen
screen_pos1.y = 0;
vec_for_screen(screen_pos1,camera); //get the world coordinates

screen_pos2.x = screen_size.x; //the screen corner on the right bottom
screen_pos2.y = screen_size.y;
vec_for_screen(screen_pos2,camera); //get the world coordinates

clamp(my.x,screen_pos1.x,screen_pos2.x); //clamp
clamp(my.y,screen_pos1.y,screen_pos2.y); //clamp

wait(1);
}
}
© 2024 lite-C Forums