Jump to content
Sign in to follow this  
BEAKSBY

Changing Camara Height

Recommended Posts

Why won't this camera script work?

I want the camera to hover over the player so they can see from above.

private "_cam";

// "create a camera object";
_cam = "camera" camCreate [position player select 0, (position player select 1) - 10, 50];
player switchCamera "_cam";
_cam camCommit 3;

Share this post


Link to post
Share on other sites

I placed the above camera script in an sqf that gets called by an addAction. There is no change in the camera angle or view. I thought it would switch to a camera view that is at the player position, 10m behind and 50m above him?

Share this post


Link to post
Share on other sites
Why won't this camera script work?

I want the camera to hover over the player so they can see from above.

private "_cam";

// "create a camera object";
_cam = "camera" camCreate [position player select 0, (position player select 1) - 10, 50];
player switchCamera "_cam";
_cam camCommit 3;

Ok 2 things come to mind.

Firstly, i think you need to set the target of the cam onto the player.

Secondly, Try attaching the the camera to the player and using some offset to get the camera to sit 50m above the player.

Alternative to attachto. Use a Loop that sets the camera position above the player every 0.02 seconds.

Share this post


Link to post
Share on other sites

bad syntax for switchCamera. What you are actually using is _cam cameraEffect ["INTERNAL","BACK"];

Camera effect creates an independent camera, switchCamera is for 1st person, 3rd person, etc. predefined camPoses.

Use a Loop that sets the camera position above the player every 0.02 seconds.

Don't. Why 0.02 seconds? Why not waituntil condition which executes on each frame?

Although AttachTo is preferred, since it can take a static offset.

Edited by zapat

Share this post


Link to post
Share on other sites

Don't. Why 0.02 seconds? Why not waituntil condition which executes on each frame?

How do would you do that?

Share this post


Link to post
Share on other sites

waituntil
{
   //everything here gets executed on each frame
   _cam setPos _toWhatever;

   //condition to exit waituntil loop. Note: no ; at the end!!
   !alive player
};

This is naturally only a prototype: setPos will run on each frame until player is dead.

Edit: I missed a !

Edited by zapat

Share this post


Link to post
Share on other sites
waituntil
{
   //everything here gets executed on each frame
   _cam setPos _toWhatever;

   //condition to exit waituntil loop. Note: no ; at the end!!
   !alive player
};

This is naturally only a prototype: setPos will run on each frame until player is dead.

Edit: I missed a !

mmm. I didnt know you could do that with waituntil.

Wouldn't that be needlessly intensive on the CPU? Like running a while command with no sleep.

Share this post


Link to post
Share on other sites

Actually it is better than while. While is scheduled, so it runs more than each frame if it can.

Waituntil condition is per frame maximum.

Naturally you can use sleeps in waituntils to save CPU cycles if necessary. But Waituntil is the easiest on each frame executor in sqf. You just need to know what you are doing (you cannot do such with while.

Share this post


Link to post
Share on other sites
Actually it is better than while. While is scheduled, so it runs more than each frame if it can.

Waituntil condition is per frame maximum.

Naturally you can use sleeps in waituntils to save CPU cycles if necessary. But Waituntil is the easiest on each frame executor in sqf. You just need to know what you are doing (you cannot do such with while.

So if you are getting 30FPS this would be equivalent to 0.0333 seconds sleep?

Share this post


Link to post
Share on other sites

Exactly.

Waituntil condition is FPS dependant.

While is CPU dependant.

Share this post


Link to post
Share on other sites

I'm still not getting the camera to remain in position above the player's offset position:

THis is called in from an addAction command:

_camera camSetTarget player;
_camera = "camera" camCreate [position player select 0, (position player select 1) - 10, 10];
onEachFrame {   
_camera attachTo [player,[position player select 0, (position player select 1) - 10, 10]]; 
// _camera setPos [position player select 0, (position player select 1) - 10, 10]; THIS ALSO DOES NOT WORK
_camera camCommit 3; 
if (missionnamespace getvariable ["place",false]) exitwith {};

}; // end of while/oneachframe

Share this post


Link to post
Share on other sites
I'm still not getting the camera to remain in position above the player's offset position:

THis is called in from an addAction command:

_camera camSetTarget player;
_camera = "camera" camCreate [position player select 0, (position player select 1) - 10, 10];
onEachFrame {   
_camera attachTo [player,[position player select 0, (position player select 1) - 10, 10]]; 
// _camera setPos [position player select 0, (position player select 1) - 10, 10]; THIS ALSO DOES NOT WORK
_camera camCommit 3; 
if (missionnamespace getvariable ["place",false]) exitwith {};

}; // end of while/oneachframe

If you are attaching the camera you do not need to run it inside the onEachFrame.

Also run the '_camera camSetTarget player; ' after you create the camera.


_camera = "camera" camCreate [position player select 0, (position player select 1) - 10, 10]; 
_camera camSetTarget player; 
   _camera attachTo [player,[0,0,50]];  
   _camera camCommit 1;  

Share this post


Link to post
Share on other sites

It did not do anything...

I've tried this too and it locks up in the camera view and won't terminate.

_camera = "camera" camCreate [(position player select 0), (position player select 1) - 10, 10]; 
_camera cameraEffect ["external", "back"]
_camera camSetTarget player; 
_camera attachTo [player,[0,0,50]];  
_camera camCommit 5;

//sleep 3;
camDestroy _camera;
_camera cameraEffect ["terminate","back"];

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

Try it the other way around.

First the effect (which kills the visuals)

Then the camera object. (which gets rid of the object itself)

If you destroy the object first, it is destroyed meaning you cannot give it a terminate effect either.

AND most importantly!!!

NEVER. And I say N.E.V.E.R. use onEachFrame command! I saw it in your other topic as well. Probably the most dangerous habit in sqf coding.

Use https://community.bistudio.com/wiki/BIS_fnc_addStackedEventHandler instead!

Reason: you cannot stack onEachFrame command. There can be only one. So it can cause unwanted behaviour.

BIS fnc stacks them though, so you can use as many as you want.

And don't forget to clean them with BIS_fnc_removeStackedEventHandler if you don't need em anymore.

Edited by zapat

Share this post


Link to post
Share on other sites

Thanks Zapat,

I did also try it with the following 2 scripts below switched and it did not work. It remains locked in the view above the player. I cannot move, or change views or use the menus. I have to end the mission to get out.

camDestroy _camera;

_camera cameraEffect ["terminate","back"];

Share this post


Link to post
Share on other sites

_camera cameraEffect ["terminate","back"];

camDestroy _camera;

Have you tried this order?

Share this post


Link to post
Share on other sites

Yes, and it remained frozen.

How would I get the camera to follow the player from 10m above and 5m behind and pan with the player as he turns, in otherwords change the 3rd person view settings? Do you know of any premade simple scripts I can paste to my sqf? I want this for part of an action that allows the player to call in emplacements and vehicles around them so they can see the terrain better.

And if I want ot go back to the default 1st person and 3rd person view I assume I press the ALT key?

Share this post


Link to post
Share on other sites

AND most importantly!!!

NEVER. And I say N.E.V.E.R. use onEachFrame command! I saw it in your other topic as well. Probably the most dangerous habit in sqf coding.

Use https://community.bistudio.com/wiki/BIS_fnc_addStackedEventHandler instead!

Reason: you cannot stack onEachFrame command. There can be only one. So it can cause unwanted behaviour.

BIS fnc stacks them though, so you can use as many as you want.

And don't forget to clean them with BIS_fnc_removeStackedEventHandler if you don't need em anymore.

Thanks for the link, I updated the other script after finding one of the issues you mentioned.

I found that it remains running even if you use exitwith.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×