Keyboard Controlled Human Movement in 3DEXCITE
In the 3DEXCITE Creative Experience application, you can make a human character move along a predefined path when a key on the keyboard is pressed. To accomplish this, we start by setting up motion behavior, then proceed to scripting an event, and finally configure a scenario in Storytelling. In this guide, we will walk you through the process of enabling keyboard-controlled human movement in 3DEXCITE, allowing precise control over your actor’s movements.
Let’s go through the process step by step!
First of all, we need to bring a human character into the scene.
Now that the human model is in place, we can shift our focus to adding motion behavior.
As a result, the human will be able to move along a path in response to our scripted event.
Before we move on to scripting the movement, let’s first define the path the human will follow.
This path will serve as the movement guide when the script is triggered.
JavaScript Techniques for Keyboard Input in 3DEXCITE
At this point, we need to set up a scripted actor to handle keyboard input and trigger the human’s movement.
var TriggerEventClass = function () {
EP.Event.apply(this, arguments);
};
TriggerEventClass.prototype = Object.create(EP.Event.prototype);
TriggerEventClass.prototype.constructor = TriggerEventClass;
TriggerEventClass.prototype.type = 'TriggerEventType';
if (!STU.TriggerEvent) {
STU.TriggerEvent = TriggerEventClass;
}
if (!EP.EventServices.getEventByType(TriggerEventClass.prototype.type)) {
EP.EventServices.registerEvent(TriggerEventClass);
}
beScript.onStart = function () {
// Code to execute when the script starts.
};
beScript.onStop = function () {
// Code to execute when the experience stops.
};
beScript.execute = function (context) {
// Executed on each frame.
// 'context.deltaTime' provides the time elapsed since the last frame.
};
beScript.onAllKeyboardRelease = function (iEvent) {
// Uncomment the following line to debug key releases.
// console.log(iEvent.key);
if (iEvent.key === this.KeyCode) {
let newEvent = new STU.TriggerEvent();
this.actor.dispatchEvent(newEvent);
}
};
Let’s break down what this script does and how it works in Creative Experience.
var TriggerEventClass = function () {
EP.Event.apply(this, arguments);
};
This defines a custom event class called TriggerEventClass. It extends the EP.Event base class, making it recognizable as an event in Creative Experience.
TriggerEventClass.prototype = Object.create(EP.Event.prototype);
TriggerEventClass.prototype.constructor = TriggerEventClass;
TriggerEventClass.prototype.type = 'TriggerEventType';
Here, we create an object prototype based on EP.Event and set a custom event type, TriggerEventType.
1 Comment on “How to control Human Movement in 3DEXCITE Using JavaScript”