ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator Height Limitation and Removal...
person icon
luposian
Registered User
Quote
2023-08-22 01:53:26

Presently, my character is limited to how high he can climb, as he's supposed to NOT be able to climb the mountains until a specific condition is met (the number of hints he's collected, per the storyline for Stage 1). The javascript file works great, as is, where it is.

The problem is, I don't know how to cancel out/delete that javascript file at the time needed. And, if I remove that file from the Luposian node, using just the code itself from the javascript file doesn't seem to work, when I try to use it as a condition.

I sense I'm either doing something wrong or not doing something right (same difference? emoji icon_grin). Here's the Javascript code:


// The following embedded xml is for the editor and describes how the behavior can be edited:
// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action
/*
<behavior jsname="behavior_LPSNHeightTH" description="Height Threshold v0.1">
<property name="threshold" type="float" default="10.0" />
<property name="slideSpeed" type="float" default="0.05" />
</behavior>
*/

behavior_LPSNHeightTH = function () {
this.lastTime = null;
};

behavior_LPSNHeightTH.prototype.onAnimate = function (node, timeMs) {
let playerPos = ccbGetSceneNodeProperty(node, 'Position');

if (!this.lastTime) {
this.lastTime = timeMs;
return;
}

var delta = timeMs - this.lastTime;
this.lastTime = timeMs;
if (delta > 200) delta = 200;

if (playerPos.y >= this.threshold) {
this.lastPosition.y -= this.slideSpeed * delta;
ccbSetSceneNodeProperty(node, 'Position', this.lastPosition);
} else {
this.lastPosition = playerPos;
}
}

Obviously, if this single javascript file contained the condition "until Book5/Hint5 is picked up, limited height. After Book5/Hint5 picked up, remove limitation", that would be ideal, but I haven't a clue how to code that (blind kitten, meet tornado). I was able to EDIT the existing code to suit my needs, but changing it is my problem. emoji icon_sad

person icon
sven
Registered User
Quote
2023-08-22 02:37:35

This script attach to some Node but not to the player.
Now if you want to disable this script you can just delete that Node you attached this script to.
With this script you need to specify the player.. ( before you attached it to the player but now you can attach it anywhere you want but you need to specify the player..
There is multiple ways how to make this happen but this is probably simplest for you currently.

// The following embedded xml is for the editor and describes how the behavior can be edited:
// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action
/*
<behavior jsname="behavior_LPSNHeightTH" description="Height Threshold v0.1">
<property name="cNode" type="scenenode" default="Player" />
<property name="threshold" type="float" default="10.0" />
<property name="slideSpeed" type="float" default="0.05" />
</behavior>
*/

behavior_LPSNHeightTH = function () {
this.lastTime = null;
this.lastPosition=null;
};

behavior_LPSNHeightTH.prototype.onAnimate = function (node,timeMs) {
var playerPos = ccbGetSceneNodeProperty(this.cNode, 'PositionAbs');

if (!this.lastTime) {
this.lastTime = timeMs;
return;
}

var delta = timeMs - this.lastTime;
this.lastTime = timeMs;
if (delta > 200) delta = 200;

if (playerPos.y >= this.threshold) {
this.lastPosition.y -= this.slideSpeed * delta;
ccbSetSceneNodeProperty(this.cNode, 'Position', this.lastPosition);
} else {
this.lastPosition = playerPos;
}
}


person icon
luposian
Registered User
Quote
2023-08-22 04:17:34

The javascript file is attached to the Luposian player node. If I delete that node, I have no character! So, that doesn't seem to be the right approach. How do we set up a condition that enables the height limitation until another condition is met, as I mentioned before?

Or maybe I'm misunderstanding what you said. But what "player" node do I create that I can easily delete at any time? Would that be, like a book or 2D overlay, like what I've done so far?

I've incorporated the new version, but unless I assign cNode to "Luposian_Player", there is no height limitation effected. So, obviously I don't understand how to use this (i.e. I'm doing something wrong). How do I conditionally delete a javascript behavior file, that's in a list of my character's behaviors? Removing a scene node, that I got. I can do that conditionally (as I've done with the books/hints), but how do I assign my character to a scene node (or vice versa) and the height limitation behavior to it, so that my character is height limited (unable to climb the mountains), until I delete the scene node? Assuming I'm understanding how you're supposed to be able to use this version of the javascript file. emoji icon_cry

person icon
sven
Registered User
Quote
2023-08-22 09:11:41

Make a cube..
attach script to that cube (my version of script)

Now first input for behavior is a scenenode- put player into it.
Second is threshold
third is slidespeed

if you dont need height limitation anymore then just delete this CUBE..and behavior will be deleted with the cube.


cNode you must assign to Luposian but dont attach script to Luposian.. then you can delete node with script.

You can make it if last book appears then delete node with script and then its done.

person icon
luposian
Registered User
Quote
2023-08-22 15:29:06

wrote:
Make a cube..
attach script to that cube (my version of script)

Now first input for behavior is a scenenode- put player into it.
Second is threshold
third is slidespeed

if you dont need height limitation anymore then just delete this CUBE..and behavior will be deleted with the cube.


cNode you must assign to Luposian but dont attach script to Luposian.. then you can delete node with script.

You can make it if last book appears then delete node with script and then its done.

So, do I need to create a new cube or can I use one of the already existing cubes in the game?

So I add the behavior to the cube and then assign Luposian to the behavior? And Luposian won’t be able to climb the mountains as long as the cube exists? And then, when I want to stop the behavior, I simply delete the cube?

person icon
sven
Registered User
Quote
2023-08-22 15:34:35

Yes.

You can use whatever node you want that you can afford to delete.

person icon
luposian
Registered User
Quote
2023-08-22 22:00:40

wrote:
Yes.

You can use whatever node you want that you can afford to delete.

I tried using Book5 (scene node), but upon doing so, I was able to climb the mountains, as though the limitation wasn't there. It would have been perfect, because I actually destroy (delete) that scene node (along with the hint (a 2D overlay)) after the last hint is shown.

Then I attached it to one of the cubes (which are always visible) and now Luposian CAN'T climb the mountains. So, apparently, the scene node has to be VISIBLE, in order for the attached height limitation behavior to work.

Is there a way to use this height limitation behavior with invisible scene nodes the same as visible scene nodes?

UPDATE! I've just verified it definitely works with the visible cube scene node! Yay! I set the delay of node deletion to 250ms, to insure almost instant availability to mountain climbing.

Just need to know if I have to work around the visible node issue or if I can actually use invisible nodes.

person icon
sven
Registered User
Quote
2023-08-22 23:02:04

If node invisible then scripts that is attached to it is stopped.

You can keep your books visible-but place them at position where player never see them (for example under the terrain)

If you choose CUBE to be storage of this script then you can make it invisible by setting transparent texture to it.. so its not visible but its there. -or set its scale very small.

Also you can make a folder and use it as storage of script.. (so there is no 3d object in scene at all.

person icon
luposian
Registered User
Quote
2023-08-23 00:35:55

wrote:
If node invisible then scripts that is attached to it is stopped.

You can keep your books visible-but place them at position where player never see them (for example under the terrain)

If you choose CUBE to be storage of this script then you can make it invisible by setting transparent texture to it.. so its not visible but its there. -or set its scale very small.

Also you can make a folder and use it as storage of script.. (so there is no 3d object in scene at all.

I went with the first choice. A nice, elegant work around. You can't see the book, yet it's (quite literally) under your feet. emoji icon_grin Tested that out and it all works perfectly. Thank you so much Sven! Onto the next goal!


Create reply:










 

  

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


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






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