Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Smooth FOV scale script

dekon_17
Registered User
Quote
2021-11-09 14:20:33

Yeah, a few days ago I made a medkit script and left it here. But, uhh, I got a brilliant idea for some feedback if player took meds. Scaling FOV of camera like if player just used a bunch of morphine syringes at once. And here we go: action that smoothly changes FOV.

The script:
/*
<action jsname = "action_FOVshift" description = "OOOOOOOOHHHHHHH">
<property name = "Camera" type = "scenenode"/>
<property name = "NewFOV" type = "float"/>
<property name = "Time" type = "int"/>
<property name = "DoWhenDone" type = "action"/>
</action>
*/

action_FOVshift = function()
{
};

action_FOVshift.prototype.execute = function()
{
var me = this;
this.registeredFunction = function() { me.ShiftFOVnew(); };

this.startTime = (new Date()).getTime();
this.endTime = this.startTime + this.Time;

this.StartFOV = ccbGetSceneNodeProperty(this.Camera, "FieldOfView_Degrees")

ccbRegisterOnFrameEvent(this.registeredFunction);
}

action_FOVshift.prototype.ShiftFOVnew = function()
{
var now = (new Date()).getTime();

if (now > this.endTime)
{
ccbInvokeAction(this.DoWhenDone);
ccbUnregisterOnFrameEvent(this.registeredFunction);
ccbSetSceneNodeProperty(this.Camera, "FieldOfView_Degrees", this.NewFOV);
}
else
{
var delta = (now - this.startTime) / this.Time;
if (delta > 1.0) delta = 1.0;

var FOV = this.StartFOV + ((this.NewFOV - this.StartFOV) * delta);

ccbSetSceneNodeProperty(this.Camera, "FieldOfView_Degrees", FOV);
}
}


As usual, now about the properties:
Camera - camera...?
NewFOV - the FOV that the script will scale to.
Time - time of scaling.
DoWhenDone - action (-s) which will be executed once FOV stopped scaling.

You can use this script for such things as aiming and... something... I guess. Anyway, feel free to use this code if you need so.

Important: this action may cause some issues with "action_AnimateScale" since it is based on this one.
It is also possible that this script can cause severe meltdown of CPU, which will lead to massive explosion of your computer, probably killing you. Author is not in charge of possible consequences.



hadoken
Guest
Quote
2021-11-09 19:39:09

Maybe nothing ultra fancy fx or coding challenge so far but nevertheless super useful. Thanks @dekon_17 for doing the work with it and sharing the result with us. Good job! Works like a charm!


forloops
Registered User
Quote
2021-11-27 18:27:50

What would the syntax and vector math needed to make an enemy scene node attempt to hide from the new player FOV, so as to attempt to flank the player or ambush her/him.
Can someone help me with an action for that?


DouweDabbe
Guest
Quote
2021-11-27 23:41:03

you wrote:
What would the syntax and vector math needed to make an enemy scene node attempt to hide from the new player FOV, so as to attempt to flank the player or ambush her/him.
Can someone help me with an action for that?



what do you mean?
this script mimics the aiming event where you look through a scope or similar. You are pointing your player to an enemy then this zoomin event happens, maybe the programmer completes that with a nice scope image, and then the player aims and fires.

Now you want the enemy to react to the zoomin event, wich is not logical as the enemy cant possibly know the players behavior.


forloops
Registered User
Quote
2021-11-28 05:11:44

Not necessarily completly zooming in, just a very small zoom, like a degree or two. I am trying build off this code. I am trying to find a way to get the enemy npc to perhaps move towards a node outside the players cone of vision, while avoiding the static geometry of the level, and looking towards and then attacking the player at random intervals.


smnmhmdy
Registered User
Quote
2021-11-28 11:50:20

@forloops If you want to detect if a node is in camera's field of vision, you could try using this:
function isInCameraView(node){
var viewOffset = 150; // how far beyond the screen edge is still considered in view
var cameraPosition = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "PositionAbs");
var position = ccbGetSceneNodeProperty(node, "PositionAbs");
position.y += 15; // tweak this value to point to the upper body of the model
var position2d = ccbGet2DPosFrom3DPos(position.x, position.y, position.z);
var sWidth = ccbGetScreenWidth() + viewOffset;
var sHeight = ccbGetScreenHeight() + viewOffset;
// view obstruction check, set hit to false to disable it
var hit = (ccbGetCollisionPointOfWorldWithLine(cameraPosition.x, cameraPosition.y, cameraPosition.z, position.x, position.y, position.z)) ? true : false;
if (((position2d.x > -viewOffset && position2d.x <= sWidth) &&
(position2d.y > -viewOffset && position2d.y <= sHeight)) && !hit) {
return true;
} else
return false;
}

It'll return true if the node is visible, and false if it's not.


forloops
Registered User
Quote
2021-11-28 14:58:18

Right on smnmhmdy:) Thanks again man...


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact