Keyboard Controlled Human Movement in 3DEXCITE
In 3DEXCITE Creative Experience application, we can make a human character move along a predefined path when a key on the keyboard is pressed. This involves setting up motion behavior, scripting an event, and configuring a scenario in Storytelling. This guide will walk you through keyboard-controlled human movement in 3DEXCITE, allowing precise control over your actor’s movement.
Let’s go through the process step by step!
The first step is to bring a human character into the scene.
Now, we need to add movement capabilities to the human model.
This will allow the human to move along a path in response to our scripted event.
Next, we define the path that the human will follow.
This path will serve as the movement guide when the script is triggered.
JavaScript Techniques for Keyboard Input in 3DEXCITE
Now, we 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);
}
};
This script is responsible for detecting a key press event and triggering an action in Creative Experience. Let’s break it down:
var TriggerEventClass = function () {
EP.Event.apply(this, arguments);
};
TriggerEventClass
.TriggerEventClass.prototype = Object.create(EP.Event.prototype);
TriggerEventClass.prototype.constructor = TriggerEventClass;
TriggerEventClass.prototype.type = 'TriggerEventType';
"TriggerEventType"
.