Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Walk and Stand animation by key

rolevix
Registered User
Quote
2018-10-11 14:26:15

Hi!
Im trying some code, but this is didn't work, im not a programmer.

Im just need to make behavior to play animation "Walk" when i press WASD, and play "Stand" when i release WASD.

This piece of code is didnt work, im just trying to test on "W" key.


behavior_LegsAnimation = function()
{

ccbRegisterKeyDownEvent("keyPressedDown1");

function keyPressedDown1(87)
{
ccbSetSceneNodeProperty(this.Object, 'Animation', this.WalkAnimation);
ccbSetSceneNodeProperty(this.Object, 'Looping', true);
}

}



Also, i was try to use built-in "Object controlled by keyboard" with 0 speed, just for animation controll, but this didnt work with A-D keys.

Any help?


just_in_case
Moderator
Quote
2018-10-12 05:24:23

I can't understand what do you mean by not working with A-D keys.....

I am assuming that you are trying to say that movement speed '0' isn't affecting the keys A and D , for your information let me tell you A-D in inbuilt behavior are used for rotation of the player not for movement so changing move speed to '0', will not affect it.
You will also need to set rotation speed to '0'.

For the piece of code.... I can't say anything untill seeing the whole behavior , because there might be problem in the properties tag or anything else......

Hope you figured it out already hy yourself or you can use inbuilt behavior...

Personally i don't think that creating a behavior for this to work with animation is really make sense...
Because if your player has diffrent animation name you have to rename them everytime...
Instead i will go with the internal behavior of switch animation...

Hope that works..


rolevix
Registered User
Quote
2018-10-12 07:09:16

I mean, in "Object controlled by keyboard", when i press W or S it play animation "Walk", but if i press A or D it not...
I need script or behabior, what can just play animation like in "Object controlled by keyboard" but with WASD keys


just_in_case
Moderator
Quote
2018-10-12 07:33:51

You can simply add behavior when a key pressed do something and change animation of the object... And when a key left up change back to idle... If that helps


rolevix
Registered User
Quote
2018-10-12 14:16:59

I was trying this, but if i press W and A both - it will stop playing animation or make it wrong...


just_in_case
Moderator
Quote
2018-10-12 19:11:43

Try using variables for animation...
And when keypressed check the variable and execute animation...


tim12345
Guest
Quote
2018-10-15 19:53:55

if you still want to use behavior script... something like this might work for you probably...

/*
<behavior jsname="behavior_LegsAnimation" description="LegsAnimation">
<property name="Object" type="scenenode" />
</behavior>
*/

behavior_LegsAnimation = function()
{
this.WKeyDown = false;
};

behavior_LegsAnimation.prototype.onAnimate = function(node)
{
if (this.WKeyDown){
ccbSetSceneNodeProperty(this.Object, 'Animation', "walk");
ccbSetSceneNodeProperty(this.Object, 'Looping', true);
}
else
ccbSetSceneNodeProperty(this.Object, 'Animation', "stand");
ccbSetSceneNodeProperty(this.Object, 'Looping', true);
}

behavior_LegsAnimation.prototype.onKeyEvent = function(key, pressed)
{
if (key == 87)
this.WKeyDown = pressed;
}



rolevix
Registered User
Quote
2018-10-15 21:36:24

Oh! Thanks tim12345! You save my life, again :)


Create reply:


Posted by: (you are not logged in)


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