A Joystick Responding To Different Angles

Hello!

I don’t know where to post my topic, I just posted it here :slight_smile:

I need some help for a joystick based game, I already copied one out of this tutorial

It’s a nice joystick, but what would be the best way to make the
joystick respond to the different angles? So when my player changes
direction, the image changes, for example from 45° to 135° it’s the
right image that appears and from 136° to 225° it’s the down image.

Like the nintendo pokemon or zelda games for example.

I hope you can understand my question ;D

 

This is what I’ve done with that joystick module:

[lua]

        function Group:move(Obj, maxSpeed, rotate)
                if rotate == true then Obj.rotation = self.angle end
                local angle = math.round(self.angle / 45) * 45  –
                local dX = Cos( Rad(angle-90) ) * (maxSpeed * self.percent)
                Obj.x = Obj.x +  dX
                local dY = Sin( Rad(angle-90) ) * (maxSpeed * self.percent)
                Obj.y = Obj.y +  dY
                --print(self.angle,angle,dX,dY)
        end

[/lua]

Note the changes I made to this function.  This forces movement to 45 degree increments only (up, up right, right, down right, etc.)

Thank you for your great work!

But now, just need a bit help :stuck_out_tongue: How could I do it with sprites? 

Thanks alot Rob Miracle,

Philippe.

I’m not a sprite expert, but they end up being display objects, wouldn’t you just pass the sprite in as Obj?

Great idea thanks!

Still have some problems to do it, but if someone found a solution, just post it! I marked the topic solved, but it’s not done at all,

Thanks,

philippe :slight_smile:

This is what I’ve done with that joystick module:

[lua]

        function Group:move(Obj, maxSpeed, rotate)
                if rotate == true then Obj.rotation = self.angle end
                local angle = math.round(self.angle / 45) * 45  –
                local dX = Cos( Rad(angle-90) ) * (maxSpeed * self.percent)
                Obj.x = Obj.x +  dX
                local dY = Sin( Rad(angle-90) ) * (maxSpeed * self.percent)
                Obj.y = Obj.y +  dY
                --print(self.angle,angle,dX,dY)
        end

[/lua]

Note the changes I made to this function.  This forces movement to 45 degree increments only (up, up right, right, down right, etc.)

Thank you for your great work!

But now, just need a bit help :stuck_out_tongue: How could I do it with sprites? 

Thanks alot Rob Miracle,

Philippe.

I’m not a sprite expert, but they end up being display objects, wouldn’t you just pass the sprite in as Obj?

Great idea thanks!

Still have some problems to do it, but if someone found a solution, just post it! I marked the topic solved, but it’s not done at all,

Thanks,

philippe :slight_smile:

Hi,

I am using joystick controller in game, but it is not detecting collisions,

so,let me know whether it supports to find collision or not?

Thankyou…

Hi,

I am using joystick controller in game, but it is not detecting collisions,

so,let me know whether it supports to find collision or not?

Thankyou…