How do I tween position between moving objects?

0 favourites
  • 9 posts
From the Asset Store
Calculate parabolic trajectories and tween objects over them.
  • I'm currently using the tween behavior for an arrow pointing at moving objects.

    When the player is near the moving object, the arrow moves smoothly to the moving object in say, 1 second.

    The problem is that when the tween is in motion, it doesn't 'update' the moving object's position X and Y so it will always end the tween too early and to an outdated position of the moving object.

    How can I solve this?

    Tagged:

  • You can keep updating the tween until the 1 second is gone

    For example, Does this help?

    https://www.dropbox.com/s/yu26488evpwmqf1/1-Tween%20Pos.c3p?dl=0

  • Hey,

    Thanks for posting that example.

    I fiddled with it a bit, but am not able to implement it just yet. This is what my code originally looks like;

    Had to code it so the arrow keeps at a steady position around the Player when it is moving and doesn't have its Target in sight.

    The tweens work, its just that they finish at an outdated position.

    It's hard to implement a different code example in your own!

    I fiddled with it but I'm not able to make it work, bit confused where to put the code, since I have an 'in' and 'out' tween so the events work differently. The arrows should move smoothly to/back when its in/out of range.

    P.S. The instance variable 'ArrowTween' in my example, I used a local variable for it first instead, but that didn't make it work. It wasn't until I replaced it with an instance variable that it worked. Maybe a bit off topic, but was wondering why that doesn't work? It should do the exact same thing.

  • Np glad helpful

    I know ruffly what you trying to do but still not very clear by looking at your events.

    This is what I see:

    Events:

    232 & 234 are the same, you just set the position at the exact (X,Y)

    235 & 237 are the same, you just set the position at the exact (X,Y)

    By tween or set position

    So we can remove that as its the same thing

    So you end up if Player has Los to the Car2 set the Arrow at the Car

    Else Arrow don't follow

    I removed the Tween

    https://www.dropbox.com/s/olqkke2y0zpw8s8/Tween%20Arrow2.c3p?dl=0

    Now you have events similar to yours so it shouldn't be any problem to integrate them into your project hopefully.

  • Yeah so my code basically works like this:

    Event 231; Arrow should always point angle at Target2

    Event 232 speaks for itself

    Event 233; I have an instance variable on the Player car, which starts by default at 1. I had to add this variable because otherwise the arrow would start tweening from Target2 towards the Player when the layout runs or position of the Player is reset and those two objects are far apart. And it should do this only once for each time the position of the Player is reset.

    So that's why the instance variable is set up like that.

    Even 234; This is where I want the arrow to keep pointing at Target2 when the tween finishes, only when within LoS. The -50 X and -50 Y is so it won't point at the centre of the object but I'm sure you got that.

    The remaining events are basically a 'copy' to make it tween back that's correct.

    Hopefully I was able to make it a bit more clear.

    I'm going to try and see if I can make it work with your new example! Thanks!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hey, Ruddy I just had a look at your events png again and realize that it wasn't exactly what you were looking for sorry for that, I must be very tired yesterday.

    So for what I see in your events, it's more simple than I thought if I got it correct this time.

    1-If the player has LOS to the Target then Arrow move to the Target Car

    2-Else PLayer has no LOS to the Target then Move the Arrow back to the PLayer

    See if this is what you need:

    https://www.dropbox.com/s/vdjenqcsjb2kxu9/4-Tween%20Arrow.c3p?dl=0

  • Hey no worries, thanks so much for this! It works like a charm. I only changed the code so it always points at the target.

    Wouldn't it be great to have tick box in the Tween behavior that says 'Update Tween until at position' or something? That would've made it a lot easier!

    Is it possible to have the Arrow to be always positioned top left by X and Y -100 pixels from the Target and Player position, so that it doesn't point at their centre all the time when it's not 'tweening'?

    Also, can the Arrow 'tween' slower? Tried changing the Timers but I couldn't see a difference.

    Thanks!

  • Np glad it was helpful

    Is it possible to have the Arrow to be always positioned top left by X and Y -100 pixels from the Target and Player position, so that it doesn't point at their centre all the time when it's not 'tweening'?

    Not sure what you mean by "So it doesn't point to the centre"

    As doesn't matter where you positioned the Arrow it will always point to the centre of the Target unless you change the set Angle.

    If you don't want to point to the centre of the target then you can just change the Arrow set Angle Action to the values you need instead of the Arrow position, it should be easy.

    ===========

    Also, can the Arrow 'tween' slower? Tried changing the Timers but I couldn't see a difference.

    You can do that by increasing the Timers the bigger is the number the slower will tween

    Here is one example of what I understood so far:

    -Arrow always point to the target no matter what

    -Set the Arrow position always at (X, Y -100) of (Target or Player)

    -Tween slower

    One thing is by tweening slower you need to let tween finish before for example goes back from target to the player so I changed the code a little bit for that.

    https://www.dropbox.com/s/pdo770n7hoc7gau/5-Tween%20Arrow.c3p?dl=0

  • Thanks man!

    Your latest example is exactly what I was looking for. I've nothing to add.

    That made my day! :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)