2 registered members (AndrewAMD, juanex),
1,247
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Camera Cod with rotate and offset
#425175
06/28/13 13:26
06/28/13 13:26
|
Joined: Jul 2011
Posts: 55 Berlin, Germany
Sammy32
OP
Junior Member
|
OP
Junior Member
Joined: Jul 2011
Posts: 55
Berlin, Germany
|
Hi ,
i have a problem with a camera code:
vec_diff(tempVect,camera.x, my.x); tempVect.z = 0; vec_normalize(tempVect,CAMERA_OFFSET);
currCameraHeight += mouse_force.y * MOUSE_FACTOR * time_step; tempVect.z = clamp(currCameraHeight, -CAMERA_OFFSET/3, CAMERA_OFFSET/3);
vec_rotateaxis(tempVect, vector(0,0,1), mouse_force.x * MOUSE_FACTOR * time_step) ; vec_add(tempVect, my.x); if(c_trace(my.x, tempVect, IGNORE_ME | IGNORE_PASSABLE)!=0){ vec_set(camera.x, target); } else{ vec_set(camera.x, tempVect); }
vec_diff(tempVect,my.x, camera.x); vec_to_angle(camera.pan,tempVect);
I need a Offset Vector for put the camera a little bit in left position and rotate for a walking like some rpg's with an Offset for a shooter position.
like the same game : state of decay, Batman, assasins creed and so on.
The player must be walk a circle with the keys a and d with a left side offset .
I hope you understand my problem an can help, please help. thank you for you time.
Best regards
Last edited by Sammy32; 06/28/13 13:32.
- 3d Gamestudio Commercial - - ANET Pro - <JAVA | PHP | HTML | Flash > DEVELOPER
|
|
|
Re: Camera Cod with rotate and offset
[Re: Sammy32]
#425178
06/28/13 13:42
06/28/13 13:42
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Use the following code to realize all kinds of offsets:
vec_set(temp,vector(negative value to place the camera behind the player, positive value to realize an offset to the left side (negative -> right side), positive value to place above player.z));
vec_rotate(temp,vector(camera.pan,0,0)); // or player pan
vec_add(temp,player.x);
vec_set(camera.x,temp);
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Camera Cod with rotate and offset
[Re: Superku]
#425180
06/28/13 13:57
06/28/13 13:57
|
Joined: Jul 2011
Posts: 55 Berlin, Germany
Sammy32
OP
Junior Member
|
OP
Junior Member
Joined: Jul 2011
Posts: 55
Berlin, Germany
|
Hi Superku, Thank you for your answer.
i can use this code snippet, because i have to many rotate axis.
i have try some different codes with an offset code and every code snippets, makes not a good result.
i Hope you or annother person can help me.
Best regards and a big Thanks
- 3d Gamestudio Commercial - - ANET Pro - <JAVA | PHP | HTML | Flash > DEVELOPER
|
|
|
Re: Camera Cod with rotate and offset
[Re: Sammy32]
#425198
06/28/13 18:23
06/28/13 18:23
|
Malice
Unregistered
|
Malice
Unregistered
|
After Superku's snip use the vec_to_angle() to make the camera look at the player. modified for manual example
// get the direction from the entity MY to the entity YOU
vec_set(temp,camera.x);
vec_sub(temp,player.x);
vec_to_angle(camera.pan,vector(temp.x,temp.y,0)); // now MY looks at YOU
EDITED because I mixed up the my and you entities.
Last edited by Malice; 06/29/13 07:07.
|
|
|
Re: Camera Cod with rotate and offset
[Re: ]
#425210
06/29/13 06:34
06/29/13 06:34
|
Joined: Jul 2011
Posts: 55 Berlin, Germany
Sammy32
OP
Junior Member
|
OP
Junior Member
Joined: Jul 2011
Posts: 55
Berlin, Germany
|
Goood Morning and thank you for you Answer Malice,
if i user this code : vec_set(temp, vector(-200, -100, 100) ); vec_rotate(temp,vector(camera.pan,0,0)); // or player pan vec_add(temp,player.x); vec_set(camera.x,temp); // get the direction from the entity MY to the entity YOU vec_set(temp,player.x); vec_sub(temp,camera.x); vec_to_angle(camera.pan, vector(temp.x, temp.y, 0)); // now MY looks at YOU
also the snipet from superku and your code snipet after that the screen roatets and rotates, the problem ist the second rotate "vec_to_angle(camera.pan, vector(temp.x, temp.y, 0)); " if i delete " vec_rotate(temp,vector(camera.pan,0,0)); // or player pan" the problem ist fixed but the "offset" is properly not right, mmmh.
My problem is, if i use this code
// Store new camera position in tempVect vec_diff(tempVect,camera.x, my.x); // The direction should be from player to camera tempVect.z = 0; // remove height vec_normalize(tempVect,CAMERA_OFFSET); // it should be CAMERA_OFFSET quants away // adjust height currCameraHeight += mouse_force.y * MOUSE_FACTOR * time_step; tempVect.z = clamp(currCameraHeight, -CAMERA_OFFSET/3, CAMERA_OFFSET/3); // Rotate with mouse movement vec_rotateaxis(tempVect, vector(0,0,1), mouse_force.x * MOUSE_FACTOR * time_step) ; vec_add(tempVect, my.x); if(c_trace(my.x, tempVect, IGNORE_ME | IGNORE_PASSABLE)!=0){ vec_set(camera.x, target); } else{ vec_set(camera.x, tempVect); } // Look at player vec_diff(tempVect,my.x, camera.x); vec_to_angle(camera.pan,tempVect);
my player walk a circle
if i user this code : camera.arc = 70; camera.clip_near = 0; my.pan -= 0.5 * mickey.x * time_step; camera.pan += ang(my.pan - camera.pan) * time_step * 0.8; camera.tilt -= 0.5 * mickey.y * time_step; camera.tilt = clamp(camera.tilt,-30,30); vec_set(cam_offset.x,vector(35,-25,40)); vec_rotate(cam_offset.x,camera.pan); vec_add(cam_offset.x,my.x); cam_pos.x = cam_offset.x + fcos((camera.pan),fcos(camera.tilt,-100)); cam_pos.y = cam_offset.y + fsin((camera.pan),fcos(camera.tilt,-100)); cam_pos.z = cam_offset.z + fsin(camera.tilt,-100); result = c_trace(vector(my.x,my.y,my.z),cam_pos,IGNORE_MODELS|IGNORE_SPRITES); if(result > 0) { vec_scale(normal,15); vec_add(target,normal); vec_set(camera.x,target); } else { vec_set(camera.x,cam_pos); }
i have a good offset
i will merge the codes for walk with a circle and have a offset , like Batman arkhan city , assasins creed and so on.
for "walk in a circle with an offset"
i hope you understand my problem and some people can help me
thank you for your time
best regards
- 3d Gamestudio Commercial - - ANET Pro - <JAVA | PHP | HTML | Flash > DEVELOPER
|
|
|
Re: Camera Cod with rotate and offset
[Re: Sammy32]
#425212
06/29/13 07:02
06/29/13 07:02
|
Malice
Unregistered
|
Malice
Unregistered
|
Please, Please .. Use code tags. So hard to read. Yes I mixed the vec_set() and vec_sub() entities
vec_set(temp, vector(-200, -mouse_force.x*MOUSE_FORCE, mouse_force.y * MOUSE_FORCE) );
clamp(temp.z, -CAMERA_OFFSET,CAMERA_OFFSET);
vec_rotate(temp,vector(camera.pan,camera.tilt,0)); // or player pan
vec_add(temp,player.x);
vec_set(camera.x,temp);
vec_set(vec_temp,camera.x);
vec_sub(vec_temp,player.x);
vec_to_angle(camera.pan,vector(vec_temp.x,vec_temp.y,0);
I removed the time_step(s) but you can add them. Also I add camera.tilt in but I'm not sure I should have, maybe Superku will correct me. Read this post about cameras and wall detection http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=424436#Post424436 Much better then this code below ..
vec_add(tempVect, my.x);
if(c_trace(my.x, tempVect, IGNORE_ME | IGNORE_PASSABLE)!=0){
vec_set(camera.x, target);
}
else{
vec_set(camera.x, tempVect);
}
camera.arc = 70;
camera.clip_near = 0;
my.pan -= 0.5 * mickey.x * time_step;
camera.pan += ang(my.pan - camera.pan) * time_step * 0.8;
camera.tilt -= 0.5 * mickey.y * time_step;
camera.tilt = clamp(camera.tilt,-30,30);
vec_set(cam_offset.x,vector(35,-25,40));
vec_rotate(cam_offset.x,camera.pan);
vec_add(cam_offset.x,my.x);
cam_pos.x = cam_offset.x + fcos((camera.pan),fcos(camera.tilt,-100));
cam_pos.y = cam_offset.y + fsin((camera.pan),fcos(camera.tilt,-100));
cam_pos.z = cam_offset.z + fsin(camera.tilt,-100);
You can do this ^ if you wan to work that hard.. Funny fcos,fsin not in the manual anymore, must still be around for compatibility. Posting a big block of code like this is hard to work with. Please now that we know your code pick direct questions from it and take them one at a time. Also you keep talking about Batman movement it would help me if you post a link to a video that show what you want to do. I have never played batman, don't really want to go fishing.
Last edited by Malice; 06/29/13 07:32.
|
|
|
Re: Camera Cod with rotate and offset
[Re: ]
#425218
06/29/13 08:56
06/29/13 08:56
|
Joined: Jul 2011
Posts: 55 Berlin, Germany
Sammy32
OP
Junior Member
|
OP
Junior Member
Joined: Jul 2011
Posts: 55
Berlin, Germany
|
Hi Malice,
thank you for your time and help i have found the problem i must use :
camera_force.pan += 2.5 * time_step;
thank you and best regards
- 3d Gamestudio Commercial - - ANET Pro - <JAVA | PHP | HTML | Flash > DEVELOPER
|
|
|
|