Jump to content

pointing a small sprite on a moving target is always behind - not just a little bit


valueerror
 Share

Recommended Posts

i have an object (see screenshot)  that is my penguin..  i add a small white image that always points to the mouse pointer and changes it's length according to the distance between the pointer and the object..

 

so it looks like the penguin is strapped to the mousepointer with a white elastic rope...   the rope is a simple phaser image (not a sprite and without physics)

 

when the penguin moves fast the position of the rope is not in the center anymore.. depending on the velocity of the sprite the rope is off 5mm to 2cm..  

 

( I am using p2 physics )

to keep the rope image always on the penguin i wrote the following 2 lines:

this shouldn't be behind because its updated on every frame - its running in the update loop and keeps the rope anchor at the penguins (hitSprite) center  (but it DOESN'T )

rope.x = hitSprite.x; rope.y = hitSprite.y;

also in the update loop there is the length and angle calculation:  (mouseanchor is the point where the mouse is)

 

rope.angle = angleBetween(mouseAnchor,hitSprite)+90;rope.height = distanceBetween(mouseAnchor, hitSprite);

i'm using custom functions to calculate the angle and the distance and it works very well when the penguin is moving very slow...   also it looks very choppy when the penguin is moving fast.. it feels like the rope image is only updated every 10 time ?? !!

 

why is the position update of the rope so much delayed ?

 

thx in advance!

 
 
 

post-6912-0-92487300-1416862493.jpg

Link to comment
Share on other sites

i made a cuple of tests and found out the REAL issue.    the physics body is totally off.  have a look at the screenshot !

 

so my flexible rope is actually pointing towards the correct point.. the center of the physics body.. but the center of the body is not the center of the sprite if the sprite is moving fast.. 

 

 

puhh..  unfortunately i alread point to the sprite.x not the sprite.body.x and as you can see in the attachment (my console log where i log body.x and sprite.x)  they are always the same..  but still the sprite is painted on a different position..  

post-6912-0-85655300-1416905819.png

post-6912-0-60848900-1416905831.png

Link to comment
Share on other sites

  • 1 year later...

hi @valueerror, you can help me ! 

i made a cuple of tests and found out the REAL issue.    the physics body is totally off.  have a look at the screenshot !

 

so my flexible rope is actually pointing towards the correct point.. the center of the physics body.. but the center of the body is not the center of the sprite if the sprite is moving fast.. 

 

 

puhh..  unfortunately i alread point to the sprite.x not the sprite.body.x and as you can see in the attachment (my console log where i log body.x and sprite.x)  they are always the same..  but still the sprite is painted on a different position..  

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...