Reverse vertical direction
Hi all! :D
How can I reverse only horizontal or only vertical direction of an active object?
At the moment I'm using the Bounce movement, but I'd prefer to use a custom way, because I'm making a breakout game, and I want the player to be able to choose with precision the direction to give to the ball, hitting it more to left or to the right.
Thank you in advance for your help! :)
Re: Reverse vertical direction
this may or may not be of help to you since it is a bit off topic, but i had an issue with the parallaxer object going in the wrong direction on the y axis. when assigning your coordinates for the object(x,y) assign the y with a negative number. Example would be -20,-30. if that works just adjust the number until you find one that is to your liking. hope that helped! :grin:
Re: Reverse vertical direction
Here's what I came up with. You can easily tweak things to suit your taste and this way you can still use the bounce movement's features.
Re: Reverse vertical direction
Thank you for your replies! :)
@clean_citrus: Thank you for your source file, it's a smart way to give the player more control over the ball. But I need something a little different: I want the ball, when it collides with the bat, to adjust its direction in base of where it collided on the bat. I mean, if the bat's sprite's width is 64, and the ball collides exactly in the center (32), it must go in the direction up (8). If it collides a bit on the right, for example 50, it must go on the right in a direction like 5, I don't know exactly.
In particular, I want the ball's direction to be a value between 3 and 13. My bat's sprite's width is 64, the ball's width is 16, and both have the action point in the center.
I thought of something like this:
direction = 3 + x
x : 11 = collision point : bat width
x = 11 * collision point / bat width
collision point = ball.x - bat.x + 32 (+32 because of the action point in the center)
So in the collision between ball and bat event, I added the action "Set direction to 3+11*(X( "Ball" )-X( "Bat" )+32)/64", but it doesn't work, because the ball always go on the right.
Could you help me again, please? Thank you very much for your help! :)
Re: Reverse vertical direction
First, make sure the hot spots are in the middle of the objects. If the bat's hot spot is on the far left, change X( "Bat" ) to X( "Bat" )+32.
Set direction to: (((X( "Ball" )-X( "Bat" ))*5)/32)+8
If that doesn't work, it's probably because MMF can't deal with floats in the middle of the expression evaluator. In that case, go (((X( "Ball" )-X( "Bat" ))+51)*5)/32
If that still doesn't work you may need to force it to a whole number: ((((X( "Ball" )-X( "Bat" ))*5)-(((X( "Ball" )-X( "Bat" ))*5) mod 32))/32)+8
Re: Reverse vertical direction
Set direction to: (((X( "Ball" )-X( "Bat" ))*5)/32)+8
should be
Set direction to: (((X( "Ball" )-X( "Bat" ))*5.0)/32.0)+8
if you want floats.
Re: Reverse vertical direction
You can just add a .0 if you want floats? I never knew that! :D
Re: Reverse vertical direction
Well now you know ;)
There's also some other stuff, such as division will come before multiplication
Re: Reverse vertical direction
Thank you very much! :)
Now it works.
Re: Reverse vertical direction
I have a silly, and probably less accurate way, to do this. Set your hotspot in the middle of your bat and have an event for the bat to ALWAYS look in the direction of the ball. Then on collision, change the direction of the ball to the direction of the bat. xD Silly, but it works in its own little way.