and if they collide then the other object will be moved by an impuls. You may avoid that by setting the correct Collision Mask Bits:to another object position
thank you , but can give me simple code to move object to another without path ?I like to use the MotorJoint to move objects to a target position. Check this example: https://www.b4x.com/android/forum/threads/xui2d-mouse-following-a-path.98895/#content
move object to another without path
thing.body.Position = X2.CreateVec2( x1, y1 )
Maybe I did not explain what I want correctly,B4X:thing.body.Position = X2.CreateVec2( x1, y1 )
can you give me simple example , thanksWell, that is for sure different!
1) calculate the direction vector by subtracting the enemy Position from the Player position
2) normalize the direction vector
3) now your approach is taken: set the LinearVelocity with this new vector from 2)
4) may be it shall go faster or slower then in step 3) you should multiply the new vector 2) with a scalar
You may add a more sofisticated solution by using "easing" (check google on 'easing')
Erel modified his Mouse Example and this is the code extract that I explained in post #7:give me simple example
Private Sub MoveEnemy
Dim v As B2Vec2 = Mouse.Body.Position.CreateCopy
v.SubtractFromThis(Enemy.Body.Position)
If v.Length > 0.7 Then ' <--- check, if they are too close to each other
v.NormalizeThis
' you could multiply that v by a scalar to change the speed like:
' v.MultiplyThis(1.5) ' >1 = faster, <1 = slower
Enemy.Body.LinearVelocity = v
Enemy.Body.SetTransform(Enemy.Body.Position, ATan2(v.Y, v.X) + cPI / 2) ' <--- turning the enemy in player direction
Else
Enemy.Body.LinearVelocity = X2.CreateVec2(0, 0) ' <--- yes, too close, therefore stop enemy
Enemy.Body.AngularVelocity = 0 ' <--- stops the spinning
End If
End Sub