Help with your scripting

entity.move() question

entity.move() question

Postby ant0N » 11 Dec 2012, 09:26

I want to make the management of your character:
Code: Select all
function onUpdate()
   if       (input.keyDown("i")==1)  then   
              entity.move             (obj, 0, 0, -0.006)
              anim.playAnimation (obj, "walk", 30, 1)
   elseif (input.keyDown("j")==1) then
              entity.turn(obj, 0, 1, 0)   
   else
             anim.playAnimation (obj, "idle", 30, 1)
   end
end

Image


I expect that if you rotate the character entity.turn(), then it will move in the direction of rotation:
Image


but he is not moving depends on the direction of the model:
Image
it is not very convenient...
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: entity.move() question

Postby StarFire » 11 Dec 2012, 10:41

You need to multiply the direction by the move speed.

Add this script to the Tech Trooper, if you want to use a different model just change the names of the animation:
Code: Select all
-- |------------------------------------------------------------------------------------
-- | .: S K Y L I N E :.    Simple Character Move Script.       
-- |------------------------------------------------------------------------------------

obj    = 0; -- | Define a global variable for our object ID
moveSpeed = 0.0009;
turnSpeed = 0.3;

function onInit(objID)   obj = objID; end

function onUpdate( td )
   --Get the direction we are facing, this is set to watch the z axis
   x,y,z = entity.getWorldOrientationByAxis( obj, 0,0,1 );
   moving = 0;

   --Here multiply the direction x,y,z by speed for each axis
   if(input.keyDown("i")==1)  then   
      entity.move(obj, moveSpeed * td * x, moveSpeed * td * y, moveSpeed * td * z)
      anim.playAnimation (obj, "walk", 30, 1)
      moving = 1;
   elseif(input.keyDown("m")==1)  then   
      entity.move(obj, -moveSpeed * td * x, -moveSpeed * td * y, -moveSpeed * td * z)
      anim.playAnimation (obj, "walk", 30, 1)
      moving = 1;
   end

   if (input.keyDown("j")==1) then
      entity.turn(obj, 0, turnSpeed * td, 0)   
   elseif (input.keyDown("k")==1) then
      entity.turn(obj, 0, -turnSpeed * td, 0)
   end
   
   if(moving == 0 ) then
      anim.playAnimation (obj, "idle", 30, 1)
   end
end


Hope this helps ;)
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 7 guests

cron