Getting Characters Moving using Lua (3 parts)

0

Whats up folks, so I got another set of tutorials for you involving getting the character moving with WASD using lua scripting as well as simple camera setups for FPS and 3rd-person.

Hopefully this aids in moving you a step closer to getting characters and things ready in the engine

or, at the very least hold you over until lumberyard team drops the long awaited 3rd person sample project!. below are the links:

Character Movement Part I

Character Movement Part II

Character Movement Part III

Ok now to go work on my actual game lol. Keep developing guys.

asked 7 years ago195 views
9 Answers
0

thanks! @REDACTEDUSER

answered 7 years ago
0

Weirdly enough @REDACTEDUSER

answered 7 years ago
0

nice! @REDACTEDUSER

answered 7 years ago
0

Check it out! https://blog.thirdkindgames.com/ We will be releasing one each week. Drop us a line if you have any feedback. I'm about to hit you up on Twitter too.

answered 7 years ago
0

I tried copying your lua script for player movement and everything works except the rotation...can you help me find what I did wrong? Here's my script:

local controller = {

Properties = {

mouseX = "",

mouseY = "",

camSpeed = 0.0,

playerSpeed = 0.0,

playerCam = {default = EntityId()},

},

}

function controller:OnActivate()


--LOCAL VARIABLES--


local rotX = self.Properties.mouseX;

local rotY = self.Properties.mouseY;


--PLAYER ROTATION--


self.MouseXId = InputEventNotificationId(rotX);

self.MInputBus = InputEventNotificationBus.Connect(self, self.MouseXId);

self.MouseYId = InputEventNotificationId(rotY);

self.YInputBus = InputEventNotificationBus.Connect(self, self.MouseYId);


--PLAYER MOVEMENT--


self.ForwardId = InputEventNotificationId("Forward");

self.FwdInputBus = InputEventNotificationBus.Connect(self, self.ForwardId);

self.BackwardId = InputEventNotificationId("Backward");

self.BwdInputBus = InputEventNotificationBus.Connect(self, self.BackwardId);

self.LeftId = InputEventNotificationId("Left");

self.LfInputBus = InputEventNotificationBus.Connect(self, self.LeftId);

self.RightId = InputEventNotificationId("Right");

self.RtInputBus = InputEventNotificationBus.Connect(self, self.RightId);

end

function controller:OnHeld(InputValue)


--LOCAL VARIABLES--


local CSpeed = self.Properties.camSpeed;

local pSpeed = self.Properties.playerSpeed;

local PlayerTM = TransformBus.Event.GetWorldTM(self.entityId);

local fwdVector = PlayerTM:GetColumn(1);

local rtVector = PlayerTM:GetColumn(0);


--PLAYER ROTATION--


if(InputEventNotificationBus.GetCurrentBusId() == self.MouseXId) then

TransformBus.Event.RotateByZ(self.entityId, -InputValue * CSpeed);

end

if(InputEventNotificationBus.GetCurrentBusId() == self.MouseYId) then

TransformBus.Event.RotateByX(self.Properties.playerCam, -InputValue * CSpeed);

end


--PLAYER MOVEMENT--


if(InputEventNotificationBus.GetCurrentBusId() == self.ForwardId) then

TransformBus.Event.MoveEntity(self.entityId, fwdVector * InputValue * pSpeed);

end

if(InputEventNotificationBus.GetCurrentBusId() == self.BackwardId) then

TransformBus.Event.MoveEntity(self.entityId, -fwdVector * InputValue * pSpeed);

end

if(InputEventNotificationBus.GetCurrentBusId() == self.LeftId) then

TransformBus.Event.MoveEntity(self.entityId, -rtVector * InputValue * pSpeed);

end

if(InputEventNotificationBus.GetCurrentBusId() == self.RightId) then

TransformBus.Event.MoveEntity(self.entityId, rtVector * InputValue * pSpeed);

end

end

function controller:OnDeactivate()

self.MInputBus:Disconnect();

self.YInputBus:Disconnect();

self.FwdInputBus:Disconnect();

self.BwdInputBus:Disconnect();

self.LfInputBus:Disconnect();

self.RtInputBus:Disconnect();

end

return controller

I have a camera child entity located behind the player and I've set the speed of the camera to .01 and the player speed to .1. I assigned the variables mouseX and mouseY to MouseX and MouseY respectively. I dragged and dropped the camera to use into the camera variable spot. Just can't seem to figure out what the problem is. :/ Thank you for all of your tutorials btw they are very helpful! :D

answered 7 years ago
0
self.MouseXId = InputEventNotificationId(rotX)
self.MouseYId = InputEventNotificationId(rotY);

missing quotes.

as a beginner, what helped me the most(except code samples) is the console debugging tool. Just add Debug.Log("anything here"); to a line and check the editor console window(shift+6 by default) to see if it runs(while game testing). You can even see variables by running Debug.Log("things" ..tostring(var)); instead. Hope u find good use of it

answered 7 years ago
0

Thank you very much @REDACTEDUSER

answered 7 years ago
0

Awesome work @Cstudios15!

answered 7 years ago
0
answered 7 years ago

This post is closed: Adding new answers, comments, and votes is disabled.