Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
How to do this?

aiming_bullets
Guest
Quote
2017-10-08 08:53:09

hey all!

i am having a problem in my game.I want to move my character using javascript but the problem is that it is not moving as i want it to be moved.

i want if a variable has value for example 10 then move to 10 diffrrent positions one by one.

let say the final position is 10 tiles ahead the player. and when the variable has value 10. then it will first move to first tile then on 2nd then 3rd and so on.

but when am using ccbsetscenenodeproperty command to move the player it driectly reaches to last position to the last tile.
i wan it to move it the by going through all the 10 tile one by one.

any ideas on how to acheive this using javascript..


wild-master
Registered User
Quote
2017-10-08 22:52:49

I created a file as an example for you.

At the beginning of a scene, a variable called "NumberOfTimesTimerHasBeenUsed" will be set, with a value of zero.

Then, a timer will run every 1000 milliseconds, which is equal to 1 second. You should change the number to the time that you want to pass between each of the ten movements.

Inside of the timer, I used this JavaScript code:
var Cube = ccbGetSceneNodeFromName("cubeMesh1");
var PositionOfCube = ccbGetSceneNodeProperty(Cube, "Position");
var NewZpositionOfCube = PositionOfCube.z + 15;


var NumberOfTimesToUseTimer = 10;
var NumberOfTimesAlreadyUsed = ccbGetCopperCubeVariable("NumberOfTimesTimerHasBeenUsed");


print(NumberOfTimesAlreadyUsed);


if (NumberOfTimesAlreadyUsed < NumberOfTimesToUseTimer) {
ccbSetSceneNodeProperty(Cube, "Position", PositionOfCube.x, PositionOfCube.y, NewZpositionOfCube);
NumberOfTimesAlreadyUsed++;
ccbSetCopperCubeVariable("NumberOfTimesTimerHasBeenUsed", NumberOfTimesAlreadyUsed);
}

print(NumberOfTimesAlreadyUsed);

You can delete the two lines that say "print". I used those while testing the code, to see the number of times the timer has been used before and after the variable is changed.

You should download the file here and test it:
https://drive.google.com/file/d/...

Open the CCB file with CopperCube, then press the Test button. When you press the spacebar, the cube will move to ten different positions, one by one, and then it will stop moving.

I used this line to move it on the Z position:
var NewZpositionOfCube = PositionOfCube.z + 15;

You should change the number "15" to the number of pixels that you want it to move every time.

If you want to move the character on the X or Y position instead and you need help, please tell me and I will show you which parts of the code need to be changed to do that.


aiming_bullets
Guest
Quote
2017-10-09 10:04:41

Will gonna checkout the ccb thanks for your help mate!


aiming_bullets
Guest
Quote
2017-10-09 10:09:15

Hey , Just tested the CCB file you have sent i already tried that method. But i don't want to use the every few seconds do something behavior to execute my javscript code.
i want to execute it when a key is pressed or clicked on something.
for example if a key pressed "A" then execute javascript.
so the problem is that you cant use every few seconds do somehing.


wild-master
Registered User
Quote
2017-10-09 23:06:00

I hope someone smarter than me appears here to help you. I wasted three hours this morning by trying to do this for you and I was unsuccessful.

The JavaScript Standard has features called setTimeout() and setInterval(), but they weren't working for me. They always caused messages like this: "setInterval is undefined."

If you go to this page, you will find a free extension from the creator of CopperCube called "Do Later":
http://ambiera.com/coppercube/do...

That extension will allow you to choose an amount of time that passes before an Action is activated, but it will only run once. I tried to modify it for a long time to add an option for choosing the number of times it will run, but I couldn't do it.

I added this line to the extension:
<property name="TimesToRepeat" type="int" default="1" />

And I added a "for loop" like this:
for (i=0;i<=this.TimesToRepeat;i++)
{
Place your ideas in these brackets.
}

In Niko's extension, he uses Date() and getTime() to count the milliseconds that pass. I tried to extend it and I couldn't.

I hope a wise person will read this and tell us how to finish my attempts.


aiming_bullets
Guest
Quote
2017-10-10 14:53:33

Thanks for your help! i appreciate that you tried to solve my problem.

Hope someone has a solution to this.
Maybe @Niko could help me. if he reads this post. a

and for set interval and set timeout they are not javscript core features they can only be used with Html elements.

anyways thanks for trying.


just_in_case
Moderator
Quote
2017-10-10 14:59:48

CcbInvokeAction this command may help you but am not sure if it will work for you or not.


ishmaru
Registered User
Quote
2017-10-10 21:06:14

aiming_bullets wrote:
and for set interval and set timeout they are not javscript core features they can only be used with Html elements.


Take a look at the js file of the "do something later" extension. It uses the Javascript Date object to do timed actions. You may be able to use that code to dow what you want.


aiming_bullets
Guest
Quote
2017-10-13 17:05:57

I don't think anybody have a perfect solution to this problem. Even Niko isn't replying.
I think the game engine is going to be dead soon.

Niko is not giving the engine time instead he is busy in developing simultors and post collapse..
While he should have to be more foccussed on developing coppercube engine.

Engine lacks a lot of functionality. The javascript Api os weak as compared to other engines. physics is not good. No support for fbx animated import.

As he is the owner of Ambiera and coppercube, at least he should have to take a look at the forum one time in a day.
But no he didn't even bother to give it a look.

If the developer himself isn't helping the users... Then how can i expect others to help me. But am glad that the forum users are more freindly and helpfull then the developer himself.

I know you are a busy person niko.
But giving the forum once in a day is not a big deal. You are invisible from these forums for weeks.

I don't know how other users manage to handle these kind of situations where their developer isn't answering to the questions.

And their issue remains unanswered.

Hope you take this game engine seriously. This game engine has a brilliant potential. But you only you can make it reach its full potential.
But if the things will continue going as they are now.

I am sorry i have to say that soon. Coppercube will be dead.!!

Hope someone can help me with my issue.. and thanks for all ypur valuable replies.


aiming_bullets
Guest
Quote
2017-10-16 15:29:32

Still no response from Niko. Am very disappointed.


aiming_bullets
Guest
Quote
2017-10-17 06:47:17

i must say that this is bad very bad. Developers are neglecting my post. this is really disappointing.

Am stuck with this thing and it makes me very frustrated.


niko
Moderator
Quote
2017-10-17 11:39:55

I didn't see this post strangley, (the forum is sending my notifications for new posts, but somehow I didn't get one for this), sorry for this.

You won't have setInterval() or setTimeout() because that is a functionality from the browsers. In standard JavaScript, you don't have something like this, that's why you will find this function only when using CopperCube with Flash or WebGL.

That's why you need to use something different. You can for example attach a "every few seconds do something" behavior to the root of your scene, and call your code, or any function inside that. With this, you can emulate that setInterval() function.

So what you want is to store an amount of tiles to move somewhere, and everytime a function is called, you need to move the object a bit of that. The solutions the other users posted here are valid, you only need to use something like the behavior I mentioned above to do this. Or like 'wild-master' mentioned, that DoLater function would also do the trick.


wild-master
Registered User
Quote
2017-10-17 12:55:31

Niko, I've been wondering if the reason why he doesn't want to use the Behavior called "Every few seconds, do something" is that he thinks it would cause a negative performance impact because it will constantly run during the whole game. His reason for wanting to achieving the same goal with the "If a key is pressed, do something" Behavior might be that he thinks the engine will ONLY check its status when a key is pressed, so his game will be faster because it won't constantly check the status of the "Every few seconds" Behavior.

Can you add some insight by describing the performance impact of the engine constantly checking the status of the "Every few seconds, do something" Behavior compared to the speed of checking whether a key is pressed with the Behavior called "When a key is pressed, do something"?

Imagine the "Every few seconds, do something" Behavior running every 1 millisecond. Would that waste more processing power compared to the "When a key is pressed, do something" Behavior?

Since he wants his object move at a speed that's slow enough for people to see, would the speed of the "Every few seconds" Behavior actually run faster than the check for a key press? I mean, if his "Every few seconds" Behavior is set to 1000 milliseconds (1 second), would the engine check for that less often than it checks the status of the keypress Behavior, thus causing it to actually waste LESS processing power than the keypress Behavior?

My guess is that the engine still needs to constantly check if a key is pressed, probably every 1 millisecond, so checking for that would have the same performance impact as the "Every few seconds, do something" Behavior. Is my guess correct? Does the check for a key press run at every 1 millisecond, essentially causing both Behaviors to have exactly the same performance impact? I'm talking about the C++ code that the engine is built with. Does the C++ code check for a keypress the same way it checks for the "Every few seconds" Behavior, causing them to both have the same speed?

He seems to want to emulate your "Every few seconds" feature inside of the "If a key is pressed" Behavior. Your answer might convince him and other future people that this is not necessary!


niko
Moderator
Quote
2017-10-17 13:19:51

Yes, a ""Every few seconds, do something" loop will run a bit slower than a dedicated "when a key pressed" handler, but really, really insignifcant slower.
Try it out, it doesn't have an impact on the framerate at all. You could have a few hundreds of these, and the framerate wouldn't suffer. And you only need one. Inside you could call multiple event handlers, if you prefer that, for speed.

It's because the engine knows that the key handler code only needs to be invoked when a key is pressed, while the "do something" handler is run every frame. In the first one, the "checking for key" is implemented then in C++, while in the second version, the checking is done by you, in JavaScript, which is a bit slower.


aiming_bullets
Guest
Quote
2017-10-31 07:28:23

@Niko can u please give me an example to how to do this...

i want my player to move when a variable says move forward = 3.

then when clicked on a button named move.
it will first move to postion "x,y,z" then after a second it will move to position "x2,y2,z2" then it will move to the position "x3,y3,z3"

thats what i was trying to do. but everyfewseconds doesn't seems to work for this..
@wildmaster also tried to sort the problem out.. but he didn't make it out.

now am all dependent on you... isn't there anyway to script something to get the desired results


Create reply:


Posted by: (you are not logged in)


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