Hey,
I need a little help with a simple project I am trying to create, yes I am a novice at this. I made a simple Pong board and have my moving paddles on each side with associated keys, I have tried multiple ways to get the ball to act the way I want, all to no avail.
I am trying to get the ball to move in a way you would want it to for this kind of game, ride on the Y-axis platform while moving on the X and Z. I get normal behaviour to begin with, then it gets quite out of control fast. I don't know what I am doing wrong, any help in the right direction would be appreciated.
This is the ball's script.
local dirX = 1
local dirZ = 1
local ballSpeed = 0.1
--local ballTimer = 1.5
--local gameTimer = 0
function Script:Start()
self.entity:SetKeyValue("event", "true")
end
function Script:UpdatePhysics()
if self.entity:GetKeyValue("event") == "true" then
self.entity:Move((dirX * ballSpeed),0 , (dirZ * ballSpeed),true)
end
end
function Script:Collision(entity, position, normal, speed)
if (entity:GetKeyValue("type") == "player") then
dirX = dirX * -1
end
if (entity:GetKeyValue("type") == "boundary") then
dirZ = dirZ * -1
end
end
Player's script (left and right paddle scripts are identical except for differing move keys)
Script.paddleSpeed = 0.2 --float "Paddle Speed"
function Script:Start()
self.entity:SetKeyValue("event", "none")
self.entity:SetKeyValue("type", "player")
end
function Script:UpdateWorld()
local window = Window:GetCurrent()
local padSpeed = self.paddleSpeed
padSpeed = padSpeed + (Time:GetSpeed()/100)
self.entity:AlignToVector(Vec3(0,0,0),2)
if window:KeyDown(Key.Q) then
if self.entity:GetKeyValue("event") == "hit" then
self.entity:Move(0,0,-padSpeed,true) --Have to move paddle back a bit or get collision issues
self.entity:SetVelocity(Vec3(0,0,0),true)
self.entity:SetKeyValue("event", "none")
elseif (self.entity:GetKeyValue("event") == "none") then
self.entity:Move(0,0,padSpeed,true)
end
end
if window:KeyDown(Key.Z) then
if self.entity:GetKeyValue("event") == "hit" then
self.entity:Move(0,0,padSpeed,true) --Have to move paddle back a bit or get collision issues
self.entity:SetVelocity(Vec3(0,0,0),true)
self.entity:SetKeyValue("event", "none")
elseif (self.entity:GetKeyValue("event") == "none") then
self.entity:Move(0,0,-padSpeed,true)
end
end
end
function Script:Collision(entity, position, normal, speed)
if (entity:GetKeyValue("type") == "boundary") then
self.entity:SetKeyValue("event", "hit")
end
end
Finally boundary script
function Script:Start()
self.entity:SetKeyValue("type", "boundary")
end
I had much more code in the ball's script but after so may times of deleting trying something else I have no clue what the best course is.