Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Chose Control Scheme

ygm7
Registered User
Quote
2017-10-30 21:58:23

Is there a way to restrict the keyboard controls to only be WASD?

Like for the FPS camera or the "Object Controlled by Keyboard" behavior, can I have it so it can only be controlled by either WASD or arrows, but not both?

In my game, I want to have two different characters, one controlled with WASD, and one controlled with the arrow keys.

Thank you


niko
Moderator
Quote
2017-10-31 07:38:23

with the built-in behaviors, that's not possible, but you could write or customize a plugin behavior for this.


ygm7
Registered User
Quote
2017-10-31 12:36:53

Hm... unfortunately I'm not much of a JavaScript user...
Okay, thank you for your answer! :)


behroz-khan
Registered User
Quote
2017-10-31 15:27:24

Hmm. Are you making a multiplayer game or something? If yes then how you create two camera views, one for 1st player second for 2nd player?


ygm7
Registered User
Quote
2017-10-31 16:05:39

Yeah, its a local top down multipler game. So one player has the arrow keys, and another has WASD.

Because it's top down, there is only one camera pointed at the play area.


ygm7
Registered User
Quote
2017-10-31 16:37:24

So, if I decide to make my own control scheme manually, I would do it using Key Events and "Change Position of Scene Node" etc.
But how would set each key to be a certain direction?

Thanks!


behroz-khan
Registered User
Quote
2017-11-01 08:20:02

Yeah that's right. But about your question I need to think, I will answer it 1 to 2 days or even today.


behroz-khan
Registered User
Quote
2017-11-03 12:14:19

Sorry that's the only way by scripting. I am also not scripter. I really hate scripting.
Sorry


wild-master
Registered User
Quote
2017-11-03 18:32:42

Hello. I created a CCB file to show you how to control two characters with one keyboard.

Player 1 will used the WASD keys, and Player 2 will use the arrow keys.

I achieved your goal with the built-in Actions and Behaviors! JavaScript isn't needed for this. I only used JavaScript to create the variables because that will be easier for you to maintain when your game is larger and you have many variables. I could've used the Action called "Set or Change a Variable", but I used eight variables, so creating them with JavaScript is easier than using that Action eight times.

I placed the variables in the Root Scene Node, inside of the Behavior called "Before first drawing, do something". (In the JavaScript window, I copied and pasted the same line eight times, and changed the name of each variable.)

Please download it here and tell me if you like it:
https://drive.google.com/file/d/...


ygm7
Registered User
Quote
2017-11-03 21:42:45

Wow, thank you very much, wild-master!
After looking through your code, I see how it was accomplished. That's what I was trying to do, but just couldn't wrap my head around it.

Just one thing:
The objects being moved are cars, so I want to use the left and right arrows/A & D to rotate and up/W to move in the forward direction -- pretty much exactly like the default keyboard move behavior.


Any ideas how to do this?
Thanks so much!


wild-master
Registered User
Quote
2017-11-03 23:10:28

Try this new CCB file:
https://drive.google.com/file/d/...

I needed to use JavaScript.

The cars in my example move slower when they drive backward.

In the JavaScript section of each Player, you'll find two lines that look like this:
moveX=(Math.sin(playerDir*Math.PI/180))*2.6;
moveZ=(Math.cos(playerDir*Math.PI/180))*2.6;

In the code sections that make the cars move backward, I changed the last number of each line from 2.6 to 1, like this:
moveX=(Math.sin(playerDir*Math.PI/180))*1;
moveZ=(Math.cos(playerDir*Math.PI/180))*1;

You should test many numbers until the cars move with the speeds that you prefer. Both lines of each code section must have the same number, so if you want your cars to move forward with a speed of 2.2, both lines for that portion must say 2.2.

In the sections that rotate each Player left and right, you should adjust the middle numbers until you're happy with the rotation speed of each car. Your most powerful car might have an amazing turning speed, while the nasty cars rotate slowly.

Right now, I set the Left rotation of each car to "0.0, -4.0, 0.0" and the right rotation to "0.0, 4.0, 0.0". You must only change the middle number.


ygm7
Registered User
Quote
2017-11-04 01:09:38

This is perfect, thank you very much.
Do you know of any way to add in acceleration?
Like in the same way that can be configured with the Controlled By Keyboard behavior.

Thank you so much.


tim12345
Guest
Quote
2017-11-04 12:01:58

acceleration can be achieved using Javascript. I have lazily modified your file with this code:

var speed = ccbGetCopperCubeVariable("speed");
var speedMax = 2.5;
var speedAcceleration = .05;
if (speed < speedMax){
ccbSetCopperCubeVariable("speed",accel);
var accel =speed += speedAcceleration;
if (speed > speedMax){
speed = speedMax;
}
}
player=ccbGetSceneNodeFromName("Player1");
curPos=ccbGetSceneNodeProperty(player,"Position");
curRot=ccbGetSceneNodeProperty(player,"Rotation");
playerDir=curRot.y;
moveX=(Math.sin(playerDir*Math.PI/180))*speed;
moveZ=(Math.cos(playerDir*Math.PI/180))*speed;
vecMove=new vector3d(moveX,0,moveZ);
newPos=curPos.substract(vecMove);
ccbSetSceneNodeProperty(player,"Position",newPos);


now the players have acceleration and deceleration
http://www.timiscool.net/acceler...


ygm7
Registered User
Quote
2017-11-04 16:45:48

Wow!
Thank you (and everyone) so much for all your help!


fvr20076
Guest
Quote
2024-01-24 19:40:53

im from france and i need to set my playing keybinds in Z Q S D pls how can i do this ?


Create reply:


Posted by: (you are not logged in)


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