The code is uggly but here is how the result looks like:

http://danken.ro/pub/arrow.mp4

'calculating the angle for arrow direction (canvas pivot)

'Calculting the desired target of the object with no gravity

'the shooting power

'create new arrow and shot

'compute the angle and velocity (this code need to improve see video)

'render the arrow shape

http://danken.ro/pub/arrow.mp4

'calculating the angle for arrow direction (canvas pivot)

B4X:

```
'xf=cursor position
'yf=cursor position
Dim Angle As Double
Angle = ATan2D(yf - Player.y, xf - Player.x)
destangle = Angle
```

'Calculting the desired target of the object with no gravity

B4X:

```
'this returns the points from a circle distance 300 dip from the player
'destx - as desired destionation on x coordonate
destx=Player.X+300dip*CosD(Angle)
desty=Player.Y+300dip*SinD(Angle)
```

'the shooting power

B4X:

`streng = Sqrt(Power(Abs(Player.x - xf),2) + Power(Abs(Player.Y - yf),2))/(Activity.Height-Player.Y)`

'create new arrow and shot

B4X:

```
Dim LaserShot As typLaser
LaserShot.X = Player.X
LaserShot.Y = Player.y
LaserShot.Angle=Angle+180
Dim time As Float
time=500-465*streng
LaserShot.Velocity_Y=-1.1*(Player.Y-desty)/time
LaserShot.Velocity_X=1.1*(Player.X-destx)/time'
LaserShot.Velocity=LaserShot.Velocity_Y
LaserShots.Add(LaserShot)'create new arrow object
'
```

'compute the angle and velocity (this code need to improve see video)

B4X:

```
LaserShot.Y= LaserShot.Y + LaserShot.Velocity_y
LaserShot.x = LaserShot.X - LaserShot.Velocity_X
'with no gravity applied the arrow follows the correct angle of the applied velocity
fall = fall - Elapsed
If fall<0 Then
LaserShot.Velocity_Y=LaserShot.Velocity_Y+1dip
fall=100
End If
LaserShot.Angle=LaserShot.Angle + streng*9*(90+360 - LaserShot.Angle )/(90+360)
```

'render the arrow shape

B4X:

```
AC.SaveState
AC.RotateCanvasAround(LaserShot.Angle,LaserShot.x,LaserShot.Y)
AC.DrawBitmapAt(bmplaser(0),LaserShot.x,LaserShot.Y)
AC.RestoreState
```

Last edited: