Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name: Password:
Ambiera Forum > CopperCube > Help with CopperCube
Change built-in behaviours?
Author Text

Registered User
2022-07-04 13:43:43

Is there any way to edit/change the built-in behaviours please?

My new game will have a few different vehicles (car/bike/planes/jetpack/boats etc). The built-in "keyboard controller" and "collide when moved" is OK for now, but not perfect....

I've made a car, plane and bike controller (using the built-in controls) - they're not bad but I would like them to be a bit better.

I'm not skilled enough to be able to make my own scripted controller yet but I could probably get my head around to edit the default Keyboard controller and collider as a start point.

Does anyone have a copy of the default "keyboard controller" and the "Collide when moved" script please?

Thank you.


Registered User
2022-07-04 16:57:44

Use the Sm Car controller from Sam

Registered User
2022-07-04 18:09:03

Hello VP, I think serguell's idea is very good to use the Sm car controller, if you want I have this behavior and I can share it here, although this initial project you shared is already excellent, it's incredibly fun to ride the bike! This game you're making reminds me of The Crew 2, where you can drive a lot of different vehicles!

Registered User
2022-07-04 21:56:41

Thanks both! Yes, I suppose I could try the SMcontroller to see if it's got the features I need, if not, I'll keep working on my own controller with the head-on collision-detection and tilt and will be adding airborne-detection and side-collision using the same method. It's just taking me way longer to do than I expected.

I may even just go back to how it was before, just keep it simple for now - that was the original plan but,as usual, I got carried away adding too much detail.

I just wish I knew which variables were used in the keyboard controller - it doesn't use ".hash.movementspeed" for the acceleration and I have no idea what variable was used for "rotation speed". If I knew those 2 things, my controller would be a lot better. They're the two things that are holding it back at the moment.

Also I love the inclination effect (on collide when moved) but it looks quite jerky on the bike - it's OK (not a big problem) but maybe it's been improved/smoothed by anyone already?

I wonder... if I just increase the number of tiles in the terrain, would that make it any smoother? I'll test it. If it works, I can increase the polycount in my map, just for the parts which have inclines.

Glad you like the bike - I made it this morning andwas fairly please with how it looks/feels so far. Not heard of "The Crew 2" - I'll check it out for inspiration and ideas.

Nice one. Thanks again both.

2022-07-05 03:41:21

This might help...not sure, but was the basis for making my own keyboard input behavior in my game - change to suit your game as needed...

<behavior jsname="behavior_Controls_Input" description="Keyboard/Mouse input">

behavior_Controls_Input = function() {
this.leftKeyDown = false;
this.rightKeyDown = false;
this.upKeyDown = false;
this.downKeyDown = false;
this.runKeyDown = false;

behavior_Controls_Input.prototype.onAnimate = function(node) {

// stop/move
if (this.leftKeyDown || this.rightKeyDown || this.upKeyDown || this.downKeyDown) {ccbSetCopperCubeVariable("move",1);}
else {ccbSetCopperCubeVariable("move",0);}

// walk/run
if (this.runKeyDown) {ccbSetCopperCubeVariable("run",1);}
else {ccbSetCopperCubeVariable("run",0);}

behavior_Controls_Input.prototype.onKeyEvent = function(code, down) {
// key codes (arrow): left=37, up=38, right=39, down=40
// key codes (WASD) : W=87, A=65, S=83, D=68

var run = ccbGetCopperCubeVariable("keyRun");

if (code == 37 || code == 65) {
this.leftKeyDown = down;
if (down) this.rightKeyDown = false;
return true;
if (code == 39 || code == 68) {
this.rightKeyDown = down;
if (down) this.leftKeyDown = false;
return true;
if (code == 38 || code == 87) {
this.upKeyDown = down;
if (down) this.downKeyDown = false;
return true;
if (code == 40 || code == 83) {
this.downKeyDown = down;
if (down) this.upKeyDown = false;
return true;
if (code == run) {
this.runKeyDown = down;
return true;

Registered User
2022-07-05 07:26:56

Robo Aw man, that's perfect - thank you!

I'll have to start again, but that will make things so much easier and may help me get understand how to start coding other things.

Really appreciate the share.
Thank you!

2022-07-05 07:55:35

I prefer to use external scripts for key events as the inbuilt behaviors for the key events are slow and have some delays executing the action, I don't know why but javascript key events are much faster.

@VP you can either use the script provided by @robo which is more specific to the task.
or you can use the script below, in the below provided script you can provide the key code that you want to use for the keypress and can execute the action only once on key down or key up, also there is an option Hold if you use that it will repeatedly execute the key down the action, useful when shooting bullets, etc.

You can check the keycodes for the keys here:-

Download the extension from here:-

For accessing the behaviors parameter, then unfortunately no, you can't access the parameters for the inbuilt behaviors, we can only do that for external scripted behaviors only.
if you want you can use the Collision detection API of CC, to create custom collide when moved behavior but the Collision detection API is really slow, and it will affect the gameplay drastically. So it is best to stick with the inbuilt collide when moved behavior.

However, you can create rays for collision detection for the front and back tires of your vehicle that is drawing only two small rays to check the collision with the ground, and based on the collision of the tires with the ground, we can create a Better inclination or mimics better simulation for the bike or car by rotating it.

For example, if the front tire has no collision with the ground then rotate the whole object on the Z or X-axis depending on the vehicle facing direction, until it touches the ground. The same goes for the rear tires as well.

Hope that bit of info is helpful or useful. Also, I really liked the BIKE movement a lot. Great job keep it up.

Registered User
2022-07-05 11:23:44

Ah, thanks for the info just_in_case Is that the same advice for all built in C+ actions - do you suggest I'm better to use external java scripts for everything - or just specifically the keyboard controller? Thanks.

Shame about the parameters but, as you pointed out, it's better not to use it anyway.

The collision "rays" is a really good idea - I made my own using a similar idea - I shoot bullets (every 70ms) from the front of the car, then move a node to the relative position of the "last bullet impact" - I have an "on proximity" event set on that node - so when the car enters it's proximity it knows it's hit a wall or a car or pedestrian or obstacle. I use the same idea for floor collision, I'm firing bullets from the base of the car to detect when it leaves the ground to stop the skid-marks being drawn in mid-air, if the car jumps off the road and leaves proximity of the last-bullet-hit node.

I also used this bullet-node method for flight-mechanics of planes and missiles: I move the game-character AI to the last-hit-bullet node. Doing this means I can move any of the character-nodes with the mouse (if I shoot directly from the camera to the camera target). This works great for planes and also missiles.

Great suggestion for the inclination also - I didn't think of using animated rotation - will definitely be smoother. Would rays from the front of the car (for head-on crash-detection) and from the 4 tyres (for inclination/floor collision-detection) become very slow - or would it be as fast as the normal "collide when moved" inclination option?

Thanks again for the extra script and info - I'll study them all and try to make my own controllers for the cars, bikes and planes in my game.

Really excited to try this.

Registered User
2022-07-05 11:28:21

Oh, just to let you know just_in_case - the link doesn't seem to work.

If I click it directly, the link is broken, if I "ctrl+click" it instead (open link in new tab), the link does open - but it's a blank page - for me (firefox) the "" file download doesn;t activate.

Would you mind re-linking it please? I can;t find it on the neophyte site.


2022-07-05 12:11:49

@veganpete, sorry for the wrong link, just updated it the link was to the discord exclusive files. You won't find this extension on as I put it as Discord exclusive. Previously it was a media attachment link not the actual link I fixed it. You can now download the file.

I am not so sure about the all the extension, but for keyboard an mouse, I always got faster results with javascript key events rather than inbuilt C++ behaviors, just like I told you with the mouse hover behavior, the inbuilt mouse hover is not that fast and it executes the action with some delay.

Inbuilt shooting action is much better than scripted raycasting it is faster and your game won't drop fps even if there are so many bullets flying around in the scene and colliding with the environment.

TBH, I don't really know the benchmark of using 4 rays from the tyres and from front of the car will have how much impact on the game performance. If you will use the shoot action there as well, then you might not see any impact. but if you use API collision detection, then definitely it will affect the gameplay but I don't know if it will be minute or huge.

But we have seen Collision detection API affecting the gameplay in @smnMhmdy's CopperCraft and in some of my own extensions.

It won't affect the game of you casting the rays, but it will slow down the game when you have an actual collision with those rays. So if there is no collision then no problem, but if there are so many rays colliding at the same time, it will definitely slow down the game.

Registered User
2022-07-05 12:39:26

Nice one! I think I'll just keep using bullets for collision-detection then, instead of using scripted Rays. I'll try bullets on the 4 tyres, for collision detection and terrain inclination with animated rotation. Will probably take me a while to work it out and implement it.

Thanks for the info and updated link - I'll definitely stop using the built-in keyboard-controller and mouse-hover and opt for a scripted version instead - but I'll leave everything else the same for now as I've put a lot of work into it.

Thank you!

2022-07-05 16:24:14

the code does not run here:

I get bugs from this point:

if (this.leftKeyDown || this.rightKeyDown || this.upKeyDown || this.downKeyDown) { etc etc.

i also think there is some logic error

Robo does:

this.rightKeyDown = down;

which is true because:

down = true;

and therefore should be formulated as:

this.rightKeyDown = true;

or am i missing something here, what you think ?

2022-07-05 16:49:20

@DouweDabbe , the @Robo's code is specific to the task, in order to make it work for you or for your game, you might need to modify it as per your needs, if it is throwing errors or is not working for you then you can modify it as per your needs.

if (this.leftKeyDown || this.rightKeyDown || this.upKeyDown || this.downKeyDown) { etc etc.

this line should not give any bugs or any errors as this is doing nothing then setting the CopperCube variable.

this.rightKeyDown = down;

the above code is correct as well, "down" here is the condition of the key press and won't always stays true. It will be true if the key is pressed and it will be false if key is released.

so when key is released
down = false
when key is pressed
 down = true

There is nothing wrong with there.
You might need to check if you have modified or if there are some other behaviors or extension conflicting with you game.

Registered User
2022-07-05 17:47:46

Hi VP, here is the behavior Sm car controller, it can be helpful if you still don't have this file! Anyone can download this behavior for the projects!

2022-07-05 22:09:46

this is an assignment and not a comparison:

this.rightKeyDown = down;

this is a comparison (with a type conversion if need be):

if ( this.rightKeyDown == down) { // then do something }

this is an exact js comparison without type conversion (and the recommended way of doing it):

if ( this.rightKeyDown === down) { // then do something }

my offline machine said this code is buggy and I do not really know why or where the problem comes from:

in NPP JSLInt says at "line 27" unexpected code expected a ")"
rewriting to see below did not help:

if ( (this.leftKeyDown==true) || (this.rightKeyDown==true) || (this.upKeyDown==true) || (this.downKeyDown==true) ) { // then do something }

CC scripting window says:
syntax error: missing ")" after condition.
so we are testing against a conmdition here, meaning:
its in a for loop or a if statement, there isnt much more in the code.
in NPP you can count all these "()" and "[]" and "{}" 's. no problem there.
Also these "if ()" and "for ()" statements are properly set up.

I like coding but js drives me nuts, sorry.
Its a tiny fragment of code, but it cost huge amounts of time.
After a while you can slam an extension together in a day, mostly derived from something similar anyway.
But then debugging, it can take days , weeks even because of the crappy tools.

So I am very interested into other peoples debugging practices.

anyways enough other things to work on ...making a bird in Blender 3d

Create reply:

Posted by: (you are not logged in)

Enter the missing letter in: "Int?rnational" (you are not logged in)




Possible Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



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