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
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, 7th_zorro), 1,203 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Camera Cod with rotate and offset #425175
06/28/13 13:26
06/28/13 13:26
Joined: Jul 2011
Posts: 55
Berlin, Germany
S
Sammy32 Offline OP
Junior Member
Sammy32  Offline OP
Junior Member
S

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 Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Use the following code to realize all kinds of offsets:
Code:
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
S
Sammy32 Offline OP
Junior Member
Sammy32  Offline OP
Junior Member
S

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

M
Malice
Unregistered
Malice
Unregistered
M



After Superku's snip use the vec_to_angle() to make the camera look at the player.

modified for manual example
Code:
// 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. crazy

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
S
Sammy32 Offline OP
Junior Member
Sammy32  Offline OP
Junior Member
S

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

M
Malice
Unregistered
Malice
Unregistered
M



Please, Please .. Use code tags. So hard to read. Yes I mixed the vec_set() and vec_sub() entities

Code:
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 ..
Code:
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);
}




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);


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
S
Sammy32 Offline OP
Junior Member
Sammy32  Offline OP
Junior Member
S

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


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