Tween Zoom (Scale) of Layers Based on Position of Object Relative to Another Object

  • In my top-down racer game, if the Car overlaps a piece of road (the Onramp), there are several layers (for now, just "Road" or "Overpass") which are meant to zoom in or out based on the lerp value of the Car on the Onramp.

    Overview:

    1. Car overlaps Onramp (single object with four different animations for its up, down, left, or right-facing position).

    2. C3 calculates either the X or Y unlerp value depending on the position of the Car and whether the Onramp is facing up/down or left/right.

    3. Using an off-screen "Zoom Meter" object with the Tween behavior, I Tween the Zoom Meter to the unlerp value as determined by the position of the Car on the Onramp.

    4. The Tween is meant to arrive at the corresponding unlerp value shortly after the Car gets to its at-that-moment position.

    5. Using the Value of the Tween, I update the scale Road and Overpass layers.

    Just in case that didn't make much sense, this is what it's supposed to look like...sort of.

    Not properly illustrated, as I stated above, is that the actual zooming/scaling will be "lagged" behind the actual position of the Car relative to its position of the Onramp. It should act like this (which is where the Tween comes in):

    C = Car

    Z = Zoom/Scale of layer

    <--C-------->

    <Z---------->

    ...then...

    <-------C--->

    <----Z------>

    ...

    <-----------> C

    <----------Z>

    Basically, the Zoom is always playing catch up to the unlerp value of the Car's position on the Onramp. If the player slows down on the Onramp or even stops, then the Tweening of the Zoom value should eventually (like, within a few seconds or LESS) match up.

    Problem is I'm having trouble properly making this work. I had it set up before where it would update the Zoom based on the at-that-moment unlerp value, but not with a delayed value.

    Here's a screen-shot of my current event/action set up:

    I hope that all made sense...

    Can someone help me see where I made my error? Thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You are re-initializing tween on every tick, this will never work.

    Why don't you use a simple lerp? Here is a demo:

    dropbox.com/s/nbagfezqonmvfca/zoomdemo.c3p

  • That...is so ridiculously simple and awesome.

    Leave it to me to find the more difficult ways of doing things. THANK YOU, so much. LOL

    To answer your question, I was aiming for the Tween feature because of its easing into its end value. Whereas lerp is more all-or-nothing. But what you have here actually works perfectly!

    ALSO, thank you for reminding me about the reinitializing of the Tween behavior. I forgot about that. When I was doing my testing, I did notice that the value for the Tween seemed to "flicker" but I didn't catch on what was really happening. I'll try to remember that next time I think Tween is the way to go.

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