Search code examples
luacoronasdkcorona-storyboard

Change direction of Corona/LUA object


HI my object is moving right to left how can i change this to from up to down ?

function movebadc1(self,event)
        if self.x < -50 then
        self.x =300
        self.y = 300
        self.speed = math.random (2,6)
        self.initY = self.y
        self.amp = math.random (20,100)
        self.angle = math.random (1,360)

        else 
                self.x = self.x - self.speed
                self.angle = self.angle + .1
                self.y = self.amp * math.sin(self.angle)+self.initY
        end
end

Regards Kevin


Solution

  • To change from right to left, to up to down, supposing you also want other behavior to remain the same, change the three following lines:

                self.x = self.x - self.speed
                self.angle = self.angle + .1
                self.y = self.amp * math.sin(self.angle)+self.initY
    

    to

                self.y = self.y + self.speed
                self.angle = self.angle + .1
                self.x = self.amp * math.sin(self.angle)+self.initX