How to calculate a point with an given center, angle and radius?

In a nutshell do this:

  1. Calculate the ‘direction vector’ from the turret center to the target.

  2. Convert that vector to a unit vector (normalize it)

  3. Make a copy of the vector from step #2 (you’ll need it  later for step #7).

  4. Scale your original normalized vector (from step #2) by the radius of the turret.  

  5. Add the vector from step #4 to the position of the turret.  

  6. Create your bullet at the < x, y > position specified by the vector from step #5.  (Be sure to add a body)

  7. Take then vector copy from step #3 and scale by the magnitude of the bullet (i.e. how fast you want it to go in pixels per second).

  8. Call set linear velocity with the <x,y> values of the vector from step #7

Thanks for the answer :slight_smile:

My idea is to create a Laser Machine that displays a laser (using the raycast function) and reflect on each obstacle.

My question is: What kind of objects can I use to make the laser beam? Drawing lines …?

Lines, rectangles, image rectangles… all will work, depending on the effect you’re looking for.

Hi.

What is the difference between properties and methods in corona?

For instance: https://docs.coronalabs.com/api/type/Body/index.html

thanks

Is this related to the initial question?  It’s not good to add new questions to a single-topic forum post… having said that:

local bob -- a local variable \_G.bill = 10 -- a global variable billy = 9 -- a global variable local function ted() -- local function end local function sue() -- global function end function susan() -- global function end ------------------------------------------------------------ ------------------------------------------------------------ local obj = {} -- A Table obj.myName = "Bud" -- A user-defined field/property on a table function obj.doit() -- A user-defined function on a table. print("HI") end obj.doit() -- Calling the function function obj.doit2( self ) -- Another user-defined function (with explicit self as first argument) on a table. print("Hi, my name is", self.myName ) end obj.doit2() -- doit2( obj ) called as a function obj:doit2() -- doit2() called as a method function obj:doit3( ) -- A user-defined method (implied self as first argument) on a table. print("Hi, my name is", self.myName ) end obj.doit3() -- doit3( obj ) called as a function obj:doit3() -- doit3() called as a method ------------------------------------------------------------ ------------------------------------------------------------ local circ = display.newCirlce(0,0,100) -- A display object circ.myName = "Bud" -- A user defined field/property on a display object. function circ.doit() -- A user defined function on a display object. print("HI") end circ.doit() -- Calling the function function circ.doit2( self ) -- Another user defined function (with explicit self as first argument) on a display object. print("Hi, my name is", self.myName ) end circ.doit2() -- doit2( circ ) called as a function circ:doit2() -- doit2() called as a method function circ:doit3( ) -- A user defined method (implied self as first argument) on a display object. print("Hi, my name is", self.myName ) end circ.doit3() -- doit3( circ ) called as a function circ:doit3() -- doit3() called as a method

Hi gyus,

When I switch (using composer) from scene1 to scene2, my display objects inserted into scene1 are visible in scene2 … ??

What i’m doing wrong? I’m using scene:insert(…) to add my display objects

Thanks

@luisxpto32,

Not seeing what that has to do with the original question.