≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
Help with a simple ship project of mine
Posted by:
(you are not logged in)
Enter the missing letter in: "I?ternational"
(you are not logged in)
Text:
[quote][b]Guest[/b] wrote: Here's the code for what you asked: [code] /* <behavior jsname="behavior_Boat" description="Move like a boat"> <property name="MinForwardSpeed" type="float" default="0.1" /> <property name="MaxForwardSpeed" type="float" default="0.2" /> <property name="ReverseSpeed" type="float" default="0.1" /> <property name="ActionOnMinForward" type="action" default="" /> <property name="ActionOnMaxForward" type="action" default="" /> <property name="ActionOnReverse" type="action" default="" /> <property name="Action" type="action" default="" /> </behavior> */ behavior_Boat = function () { this.mode = null; this.keyA = false; this.keyB = false; this.lastTime = Date.now(); }; behavior_Boat.prototype.onAnimate = function (node) { var now = Date.now(); var delta = now - this.lastTime; var pos = ccbGetSceneNodeProperty(node, "Position"); switch (this.mode) { case 1: pos.x += this.MinForwardSpeed * delta; ccbSetSceneNodeProperty(node, "Position", pos); ccbInvokeAction(this.ActionOnMinForward); break; case 2: pos.x += this.MaxForwardSpeed * delta; ccbSetSceneNodeProperty(node, "Position", pos); ccbInvokeAction(this.ActionOnMaxForward); break; case -1: pos.x -= this.ReverseSpeed * delta; ccbSetSceneNodeProperty(node, "Position", pos); ccbInvokeAction(this.ActionOnReverse); break; case -2: ccbInvokeAction(this.Action); break; default: // Do nothing break; } this.lastTime = now; } behavior_Boat.prototype.onKeyEvent = function (key, pressed) { if (key == 87 && pressed) { if (!this.keyA) { this.mode = 1; } if (this.keyA) { this.mode = 2; } } if (key == 83 && pressed) { if (!this.keyB) { this.mode = -1; } if (this.keyB) { this.mode = -2; } } if (key == 87 && !pressed) { this.keyA = true; this.keyB = false; } if (key == 83 && !pressed) { this.keyB = true; this.keyA = false; } } [/code] Copy the code, paste it into a text file, and save it as behavior_Boat.js. Restart CC and you should be good to go. I assume you're planning on rotating the world around the boat with A and D? You didn't mention anything about that so I just did what was in your post. Let us know if you need any more help. Cheers.[/quote]
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