Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Camera Collision #207654
05/21/08 13:45
05/21/08 13:45
Joined: Oct 2007
Posts: 27
S
Skeksis Offline OP
Newbie
Skeksis  Offline OP
Newbie
S

Joined: Oct 2007
Posts: 27
I've been using the Kingdom Hearts movement and camera for a while now, and never really had any problems when I was using blocks in wed. Now all my levels are models, and I'm having issues with clipping. I've been trying for the past few days to solve this but haven't been able to. I'm wondering if someone could help me out, I just want the camera to not clip through models, any help will be appreciated. Below is the camera function.

FUNCTION handle_camera() {
camera_pan -= mouse_force.x * 12 * time;
camera_tilt += mouse_force.y * 8 * time;
camera_tilt = clamp(camera_tilt,-70,50);

camera.pan = camera_pan;
temp = fcos(camera_tilt,-camera_distance);
vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 20 + fsin(camera_tilt,-camera_distance)));

temp = min(1,2 * time);
camera.x += temp*(camera_move_to.x - camera.x);
camera.y += temp*(camera_move_to.y - camera.y);
camera.z += temp*(camera_move_to.z - camera.z);

vec_diff(temp.x,camera.x,my.x);
vec_normalize(temp.x,16);
vec_add(temp.x,camera.x);


IF (c_trace(my.x,temp.x,ignore_me) > 0) {
vec_diff(temp.x,my.x,target.x);
vec_normalize(temp.x,16);
vec_set(camera.x,target.x);
vec_add(camera.x,temp.x);
}

vec_diff(temp.x,my.x,camera.x);
vec_to_angle(camera.pan,temp.x);
}

Last edited by Skeksis; 05/21/08 13:46.
Re: Camera Collision [Re: Skeksis] #207658
05/21/08 14:27
05/21/08 14:27
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
I'm not sure but changing this line:
IF (c_trace(my.x,temp.x,ignore_me) > 0) {

to
IF (c_trace(my.x,temp.x,ignore_me) != 0) {

could solve the problem.
Reason:
c_trace returns a value smaller than zero if it hit a face/polygon from behind.
That happens is if the position it traces from is inside of a model.

Re: Camera Collision [Re: Xarthor] #207702
05/21/08 18:37
05/21/08 18:37
Joined: Oct 2007
Posts: 27
S
Skeksis Offline OP
Newbie
Skeksis  Offline OP
Newbie
S

Joined: Oct 2007
Posts: 27
I just tried that, and unfortunately it didn't help

Re: Camera Collision [Re: Skeksis] #207704
05/21/08 18:51
05/21/08 18:51
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
So, how does the camera behave?
Does it just go through models like through "air" ?
Maybe you could set the use_polygon flag in the c_trace to force better detection.
But this is only guessing in the dark...

Re: Camera Collision [Re: Xarthor] #207712
05/21/08 20:26
05/21/08 20:26
Joined: Oct 2007
Posts: 27
S
Skeksis Offline OP
Newbie
Skeksis  Offline OP
Newbie
S

Joined: Oct 2007
Posts: 27
Yeah, the camera is passing through models. I've just done a few tests and I think I need to place the camera inside an entity so then I can use the collision box of the entity, if that makes sense. I'm not too sure how to do this, going to give it a go tomorrow.

Re: Camera Collision [Re: Skeksis] #207713
05/21/08 20:45
05/21/08 20:45
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
You could also check the position with:
c_content(VECTOR* pos, mode)
(where as mode is not used yet)

result = c_content(temp.x,0);
If its inside a model the you pointer will be set by this instruction.

Re: Camera Collision [Re: Xarthor] #207721
05/21/08 21:09
05/21/08 21:09
Joined: Oct 2002
Posts: 799
Germany->Bavaria->Nuremberg
C
Christian__A Offline
User
Christian__A  Offline
User
C

Joined: Oct 2002
Posts: 799
Germany->Bavaria->Nuremberg
I allways used an entity as "carrier" for the camera and moved it with c_move - the solution worked good and was easy to handle.


MfG, Christian__A. Visit my Site: www.chris-a.de


Re: Camera Collision [Re: Christian__A] #207725
05/21/08 21:40
05/21/08 21:40

F
Fear411
Unregistered
Fear411
Unregistered
F



does you model have the polygon or box flag attached?

Re: Camera Collision [Re: Skeksis] #207991
05/23/08 21:39
05/23/08 21:39
Joined: Oct 2002
Posts: 2,256
Oz
L
Locoweed Offline
Expert
Locoweed  Offline
Expert
L

Joined: Oct 2002
Posts: 2,256
Oz
You can first try changing:

IF (c_trace(my.x,temp.x,ignore_me) > 0) {
To
IF (c_trace(my.x,temp.x,ignore_me+use_box) > 0) {

If that doesn't fix it you can also make 16 a larger number in

vec_normalize(temp.x,16);
For example:
vec_normalize(temp.x,32);

That the larger that number is the farther back the camera will be placed from collision point (Target) on model or block.

Although I would write code like this if using use_box and c_trace:

c_trace(my.x,temp.x,ignore_me+use_box);
IF (trace_hit) {
vec_diff(temp.x,my.x,target.x);
vec_normalize(temp.x,16); // make 16 larger to pull camera farther off of collision point
vec_set(camera.x,target.x);
vec_add(camera.x,temp.x);
}


Loco


Professional A8.30
Spoils of War - East Coast Games
Re: Camera Collision [Re: Locoweed] #209941
06/06/08 20:11
06/06/08 20:11
Joined: Oct 2007
Posts: 27
S
Skeksis Offline OP
Newbie
Skeksis  Offline OP
Newbie
S

Joined: Oct 2007
Posts: 27
Thanks for the help, I think I've fixed it now.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1