[Solved] Constrain x velocity of objects in scene in relation to y velocity of actor
I'm making an endless runner type game where the player only moves up and down, but objects in the scene come from right to left (similar to flappy bird). I'm trying to constrain the speed of said objects to the player's velocity. While in theory I was thinking that this would make the movement seem more natural, and give more of an illusion that the player is moving to the right when in fact the scene is moving left. Instead of lifelike the movement is erratic... so to work around this, what I'm trying to do is set the objects linear velocity in X to -300 unless the player's velocity in y is above 133 or below -133. I know I'm just not thinking it through right as this should be fairly simple to achieve and I need some help!
Here's what I have so far
attribute game.player_velocity_Y < -133
attribute game.player_velocity_Y >133
constrain self.motion.linear velocity.x to game.player_velocity_Y *1.5
otherwise
constrain self.motion.linear.velocity.x to -300
As one would expect, when the player's velocity is positive, the object's velocity changes to a positive resulting in a left to right motion (or the object appearing to move away from the player). I'm trying to constrain the direction to always be negative so the objects always move right to left.
Do I need to give up on linear velocity and use a move behavior, or (as I'm sure there is) is there a programmatic way to accomplish this?
BTW, the way I've got the player's velocity tracked is by creating a game level attribute and constraining the player's velocity in y to that attribute (game.player_velocity_Y) in the player's backstage.
Comments
nm, I got it.. just had to change the constrain behavior in the player's backstage to a rule where if the player's velocity > 0, the attribute is constrained to -self.motion.linear velocity.Y otherwise it's constrained to self.motion.linear velocity.Y
Guess I just had to post the question before my brain would work