Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Responds to keyboard input to move a character.
#include <Urho3D/Engine/Application.h>
#include <Urho3D/Input/Input.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/Graphics/StaticModel.h>
#include <Urho3D/Graphics/Model.h>
using namespace Urho3D;
class InputApp : public Application {
public:
InputApp(Context* context) : Application(context) {}
void Setup() override {}
void Start() override {
scene_ = new Scene(context_);
Node* node = scene_->CreateChild("Player");
node->CreateComponent<StaticModel>()->SetModel(GetSubsystem<ResourceCache>()->GetModel("Models/Box.mdl"));
playerNode = node;
}
void Update(float timeStep) override {
Input* input = GetSubsystem<Input>();
if(input->GetKeyDown(KEY_W)) playerNode->Translate(Vector3(0,0,1)*timeStep);
if(input->GetKeyDown(KEY_S)) playerNode->Translate(Vector3(0,0,-1)*timeStep);
}
private:
SharedPtr<Scene> scene_;
Node* playerNode;
};
URHO3D_DEFINE_APPLICATION_MAIN(InputApp)Urho3D is an open-source, cross-platform 2D and 3D game engine written in C++ with optional AngelScript and Lua scripting. It provides a lightweight, flexible environment for building games and real-time simulations.
Origin & Creator
Urho3D was created in 2007 by the Finnish developer Jukka Jylänki, later developed and maintained by a community of contributors.
Industrial Note
Urho3D is valued by developers seeking a lightweight, open-source engine with full access to C++ code, cross-platform deployment, and integrated physics and rendering systems.