Jump to content

Entity::SetInput


Chris Vossen
  • //s3.us-east-2.amazonaws.com/leadwerksstorage/ #include "App.h"<br /><br />using namespace Leadwerks;<br /><br />App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}<br /><br />App::~App() { delete world; delete window; }<br /><br />Entity* player = NULL;<br /><br />bool App::Start()<br />{<br /> window = Window::Create();<br /> context = Context::Create(window);<br /> world = World::Create();<br /> camera = Camera::Create();<br /> camera->SetRotation(35,0,0);<br /> camera->Move(0,0,-8);<br /> Light* light = DirectionalLight::Create();<br /> light->SetRotation(35,35,0);<br /> <br /> //Create the ground<br /> Model* ground = Model::Box(10,1,10);<br /> ground->SetPosition(0,-0.5,0);<br /> ground->SetColor(0.0,1.0,0.0);<br /> <br /> //Create a shape<br /> Shape* shape = Shape::Box(0,0,0, 0,0,0, 10,1,10);<br /> ground->SetShape(shape);<br /> shape->Release();<br /> <br /> //Create a character<br /> player = Pivot::Create();<br /> Entity* visiblecapsule = Model::Cylinder(16,player);<br /> visiblecapsule->SetScale(1,2,1);<br /> visiblecapsule->SetPosition(0,1,0);<br /> player->SetMass(1);<br /> player->SetPhysicsMode(Entity::CharacterPhysics);<br /> <br /> return true;<br />}<br /><br />bool App::Loop()<br />{<br /> if (window->Closed() || window->KeyDown(Key::Escape)) return false;<br /> <br /> Time::Update();<br /> <br /> float move = (window->KeyDown(Key::Up) - window->KeyDown(Key::Down))*4;<br /> float strafe = (window->KeyDown(Key::Right) - window->KeyDown(Key::Left))*4;<br /> player->SetInput(0,move,strafe);<br /> <br /> world->Update();<br /> world->Render();<br /> context->Sync();<br /> <br /> return true;<br />} function App:Start()<br /> --Create a window<br /> self.window = Window:Create()<br /> self.context = Context:Create(self.window)<br /> self.world = World:Create()<br /> local camera = Camera:Create()<br /> camera:SetRotation(35,0,0)<br /> camera:Move(0,0,-8)<br /> local light = DirectionalLight:Create()<br /> light:SetRotation(35,35,0)<br /> <br /> --Enable navmesh debugging<br /> camera:SetDebugNavigationMode(true)<br /> <br /> --Create the ground<br /> local ground = Model:Box(10,1,10)<br /> ground:SetPosition(0,-0.5,0)<br /> ground:SetColor(0.0,0.25,0.0)<br /> <br /> --Create a shape<br /> local shape = Shape:Box(0,0,0, 0,0,0, 10,1,10)<br /> ground:SetShape(shape)<br /> shape:Release()<br /> <br /> --Create a model<br /> --This is an obstacle the player will walk around<br /> self.entity = Model:Box(1,1,3)<br /> self.entity:SetColor(0.0,0.0,1.0)<br /> self.entity:SetPosition(0,5,0)<br /> self.entity:SetMass(1)<br /> <br /> --Create a shape<br /> local shape = Shape:Box(0,0,0,0,0,0,1,1,3)<br /> self.entity:SetShape(shape)<br /> shape:Release()<br /> <br /> --Enable navigation obstacles<br /> ground:SetNavigationMode(true)<br /> self.entity:SetNavigationMode(true)<br /> <br /> --Create a character<br /> self.player = Pivot:Create()<br /> local visiblecapsule = Model:Cylinder(16,self.player)<br /> visiblecapsule:SetScale(1,2,1)<br /> visiblecapsule:SetPosition(0,1,0)<br /> self.player:SetPosition(-4,0,0)<br /> self.player:SetMass(1)<br /> self.player:SetPhysicsMode(Entity.CharacterPhysics)<br /><br /> return true<br />end<br /><br />function App:Loop()<br /> <br /> if self.window:Closed() or self.window:KeyHit(Key.Escape) then return false end<br /><br /> Time:Update()<br /> <br /> local move = ((self.window:KeyDown(Key.Up) and 1 or 0) - (self.window:KeyDown(Key.Down) and 1 or 0))*4<br /> local strafe = ((self.window:KeyDown(Key.Right)and 1 or 0) - (self.window:KeyDown(Key.Left) and 1 or 0))*4<br /> self.player:SetInput(0,move,strafe)<br /><br /> self.world:Update()<br /> self.world:Render()<br /> self.context:Sync()<br /><br /> return true<br />end False

This functions set the movement parameters of an entity that uses the CharacterPhysics physics mode.

 

When an entity uses character physics, the physics will control the object's rotation, and calls to Entity::SetRotation() and similar functions will have no effect.

Syntax

  • void SetInput(const float& angle, const float& move, const float& strafe=0, const float& jump=0, const bool crouch = false, const float maxaccel = 1, const float maxdecel = 0.5, const bool detailed = false, const float maxrotationspeed=5.0)

Parameters

  • angle: the angle the character faces.
  • move: the forward movement of the character.
  • strafe: the horizontal movement of the character.
  • jump: the jumping force to apply.
  • crouch: set to true for crouching mode (included for future development)
  • maxacceleration: the maximum acceleration the character may use to speed up.
  • maxdecelleration: the maximum acceleration the character may use to slow down.
  • detailed: set this to true for characters that have a camera mounted on them. This will provide more accurate physics, but will also be more expensive to calculate.
  • maxrotationspeed: this is the maximum speed the entity can turn, in degrees per physics step.

Remarks

The input values should not be modulated by the application speed. The physics system will automatically adjust motion according to the framerate.


User Feedback

Recommended Comments

Make sure you don't multiply the input values by Time:GetSpeed(). It will cause a really bad "rubber band" effect.

Share this comment


Link to comment
Share on other sites


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...