- Newest
- Most votes
- Most comments
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.
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
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
This post is closed: Adding new answers, comments, and votes is disabled.
Relevant content
- asked 5 years ago
- asked 6 years ago
- AWS OFFICIALUpdated 4 years ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago