How do I stack movement with a sine behavior?

0 favourites
  • 3 posts
From the Asset Store
Stacking tower
$12 USD
25% off
Stacking tower is a game to try to make the tower higher
  • So let's say I have attached to my character a basic platform movement.

    I then want let's say a Pet to follow my player, and attach a sine behavior on vertical. (So it floats up and down)

    When I do this, the sine behavior acts as if it doesn't work. If I don't have the pet follow the player, it works fine, but as soon as I do (Either through pinning or whatever) it doesn't anymore.

    Now I understand why this is happening at some level, but intuitively it shouldn't. Basically it's just overriding the sine behavior in favor of maintaining the position you asked it to follow.

    In other game engines this is usually no big deal. Because you have things like local position and world position. Something where you can have your player move in world position, have your pet follow in world position AS WELL as having the pet have it's own local position to move within (the floating up and down)

    All this is usually calculated for you and presented as a 'parenting' system.

    Just wondering if people have a solution for this outside of just doing the math. It seems like a no brainer feature for such a user friendly tool as Construct, but I get that the devs have other things take priority or if it exists already, I have no clue where it is.

    Some help on this would be amazing :D

  • The solution I have now is as follows

    I basically determine the sine by code.

    I create my own Magnitude variable (To determine how far it will move)

    And created a Speed Variable (To determine how fast)

    And I just incrementally add to a MoveAmount Variable (To make sure the sine function is constantly adding)

    And just get the player's position based on what I want to sine, and it just works

    Looks something like this.

    • Is Player Visible >
    • Set Position of Pet X = to Player.X + some offset value>
    • Set Position of Pet Y = to Player.Y + (sin(MoveAmount) * Magnitude)>
    • MoveAmount = MoveAmount + Speed.

    But Again if there is a built in function for this, i'd love to know.

    Also I reset my MoveAmount to 0, once sin(MoveAmount) = 0. Just so I don't have a value forever counting up.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • robotpencil there isn't a built in function. However, you can tell the sine behavior to just calculate a value... and then manually add it like you were doing. (so you don't have to do the math).

    I made a quick sample, based on the platformer template. All I added was a pet spite, and gave it two instance variables: Yoffset to track the pet's Y position in relation to the player. And dx, which tells us how fast the pet is moving in the x direction (so we can smoothly slow it down).

    Every tick, the pet's Y position is set to the current Yoffset + the sine value. And then we try to keep the pet in range of the player... sounds like you are pretty much doing the same thing.

    https://www.rieperts.com/games/forum/petfollow.capx

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