Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Height limmit !!

thantoan
Registered User
Quote
2017-09-09 06:42:23

I want to set the player's climb height limit, any good idea ??


wild-master
Registered User
Quote
2017-09-10 01:22:50

I tried to do your idea and I was able to achieve it for you.

You must use use a variable to track the vertical position of your character.

The vertical position is called the Y axis. You must create another variable that sets the the maximum height allowed by your character, and then compare that variable to your character's current position on the Y axis.

To do this, follow the instructions in this picture:

🔎︎


If you can't see the picture, just do this:

Click on the highest item on the SceneGraph Explorer, which is the name of the scene.

After that, you must click on its "Behavior" tab.

Then you must press the Plus shape to add a behavior.

Hover over the one that says "Behaviors triggered by events", and click the line that says "Every few seconds do something".

In the properties section for this behavior, set the "IntervalMS" setting to 30, so it will happen very often.

The other property says "Action" and it says "not set". Click the space that says "not set" and a button with three dots will appear. Click it.

When you click the button with the three dots, a small window will open. You must click the button with the Plus shape to add a behavior.

Press the Plus shape, hover over "Variables and Text", and click the line that says "If a variable has a value do something."

In the properties section for this Action, put this as the name of the variable: "ShouldPlayerBeForcedToStopMovingHigher", without the quotation marks.

In the "If" section, choose "Is equal to (=)".

Set "ValueType" as "Value".

Set "Value" as "1", without the quotation marks.

In the "Action" section, click the three dots to choose an Action.

A new window will open, and you must press the Plus shape again.

After you press the Plus shape, hover over "Special" and click "Execute JavaScript".

In the box below, you will see the word "JavaScript" with an empty space. Click the empty space, and a button with three dots will appear.

Click the three dots to open a window with an empty text box.

In that window, you must copy the code below (Remember to put the name of your character's node in the quotation marks):

var player = ccbGetSceneNodeFromName("Put the name of the node of your character here");

var PositionOfPlayer = ccbGetSceneNodeProperty(player, "Position");

ccbSetSceneNodeProperty(player, "Position", PositionOfPlayer.x, 285, PositionOfPlayer.z);

ccbSetCopperCubeVariable("CurrentPositionOfPlayer", PositionOfPlayer);


After you do that, you must not change the "Else" section. Leave it as "not set". Now press the "Ok" button.

After that, you must press the Plus shape in the Behavior section of the Scene again.

Press the Plus shape, hover over "Behaviors triggered by events", and press "Every few seconds do something".

Set its "IntervalMS" setting to 30.

Then you must click the three dots in the "Action" section.

A window will open. Press the Plus shape, hover over "Special", and click "Execute JavaScript".

After you click it, you will see the word "JavaScript" with an empty space again. Click the button with the three dots in the empty space.

(I need to split this message because the forum says it's too long for one post. Please read my next post below.)


wild-master
Registered User
Quote
2017-09-10 01:28:43

(This is a continuation of my previous post. My previous message reached the character limit for one post, so I needed to split it.)

After you click the three dots, an empty text box will appear, and you must copy and paste the code below into it (Remember to put the name of your character's node in the quotation marks):

var player = ccbGetSceneNodeFromName("Put the name of the node of your character here");

var PositionOfPlayer = ccbGetSceneNodeProperty(player, "Position");

ccbSetCopperCubeVariable("CurrentPositionOfPlayer", PositionOfPlayer);

var MustNeverMoveHigherThanThisYposition = 300;

if (PositionOfPlayer.y > MustNeverMoveHigherThanThisYposition) {
ccbSetCopperCubeVariable("ShouldPlayerBeForcedToStopMovingHigher", 1);
} else {
ccbSetCopperCubeVariable("ShouldPlayerBeForcedToStopMovingHigher", 0);
}


After you do that, you must press the "Ok" button, and then also press the next "Ok" button.

Now, when your character moves higher than a Y position of 300, it will be pushed downward to force it to stay below the limit.


Search my message for the part that says "300" and change that number to the Y position that you want as the height limit in your game.

You should also search my message for the part that says "285" and change it to the number that you want your character to be pushed down to. I decided to push the character down because I'm afraid of the chance of your character being stuck if he is not pushed down by the engine.

I uploaded a CopperCube project file with a sample of my idea. You can download it here:
https://drive.google.com/file/d/...

Test it to see if you can understand how it works! Open the project file, and then press the Test button to try it.

When you press the spacebar, the box will move higher. The text on the screen will show the current height of the box. Watch what happens when its Y position is higher than 300! It will be forced to move lower!


thantoan
Registered User
Quote
2017-09-10 06:04:50

thank you very much !


just_in_case
Moderator
Quote
2017-09-13 00:38:58

I posted a behavior for this a long time ago... Named as behavior_Altitude meter.... You can use that behavior to show the current altitude on the overlay.. and can check if the player reaches to a certain altitude then do something......


wild-master
Registered User
Quote
2017-09-13 01:38:24

Thanks, just_in_case! I didn't notice it before.

I'll add these links that discuss your contribution because thantoan might be interested:
http://ambiera.com/forum.php?t=5...
http://ambiera.com/forum.php?t=5...


just_in_case
Moderator
Quote
2017-09-13 02:08:02

@wild-master , thanks for linking them here... I was so lazy to crawl the posts in forum.. hehheh


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internationa?" (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