Hi kinda asked this yesterday but got no answer, so i’ll try a second time. Trying to get my head around OOP. Essentially I want to overide a objects current move function with a new one or change its class???
Maybe my logic is all wrong hence why im asking for help, want to get it working the best way. Heres what I have done but I have a feeling its a bad method, could someone please let me know if its ok to redeclare the move function like I have???
[code]
local Angledetection = {}
function Angledetection.new(param)
local obstacle = require(“Obstacle”).new(param)
obstacle.superMove = obstacle.move
local travel = 0
local angle
local atanIt = math.atan2
local RADIANS_TO_DEGREES = 57.2957795 --180 / pi = 57.2957795
function obstacle:move(yOffset,tDelta,targetY,targetX)
self:superMove(yOffset)
angle = atanIt(targetY - self.y, targetX - self.x) * RADIANS_TO_DEGREES – work out angle between target and missile
if angle < 0 then
travel = travel + 1
if travel < 300 then
self.rotation = self.rotation + 3
else
function obstacle:move(yOffset,tDelta)
self:superMove(yOffset)
local speed = param.speed
local cosIt = math.cos
local sinIt = math.sin
local angle = 330 * (math.pi/180)
local angle = atanIt(aimY - self.y, aimX - self.x) – work out angle between target and missile
self.rotation = self.rotation - 8
local newSpeed = speed * tDelta
local originX = self.x + (cosIt(angle) * newSpeed) – update x pos in relation to angle
local originY = self.y + (sinIt(angle) * newSpeed) – update y pos in relation to angle
self.x, self.y = originX, originY
if originX > 420 or originY < - 40 or originX < - 40 then
obstacle:removeEventListener(“collision”, obstacle)
obstacle:removeSelf()
obstacle = nil
return
end
end
end
end
end
return obstacle
end
return Angledetection
[/code] [import]uid: 118379 topic_id: 23149 reply_id: 323149[/import]
[import]uid: 52491 topic_id: 23149 reply_id: 92712[/import]