Need help inverting the X axis on my paddle

…my 15.5 should have been 16… there are 16 blocks aren’t there… sorry, normally I would test it before posting. On mobile at the moment.

@Rob did those changes and both were the same problem unfortunately.

@Joao_Dalvi I attempted that code before with the minus, but it just shoved the paddle to the right side of the screen.

Hi Aron, so it’s working, but leaving a little bit of padding on either side depending which way it goes, is that correct?

When you start the scene, are they perfectly aligned at the beginning, e.g. vertically align (in the middle of the scene)?

1 Like

It appears to only be the right-side that it’s leaving room on both paddles. The top one hits left when the bottom one hasn’t hit the right one and the bottom one hits left when the top one hasn’t like the image in one of the earlier posts.

Aron, the problem probably is what Rob just said, the game space is out of the center, the x position should be half the game space width. Can you send a print of the inspector of the play space?

I renamed and re-prefabed the playspace in this instance because there are now two lose-colliders. So far the game is a bit too difficult, so that’s something I’ll work out later and the playspace will be quite different due to a previous topic where Rob helped me with programming the lives counter at the top: Making lives in Block Breaker

note:

I apologise for sounding short with you earlier. I was getting frustrated and I’ve been suffering a back problem from my second job, caught a cold and doubts keep trying to slip in to scream “Ah-ha! You suck and you’ll never improve!” but those aren’t excuses so I wanted to apologise for being a bit frustrated and coming off as ****ed off earlier in the topic. I kind of wish I didn’t want to add this to the game, but at the same time the more things I learn (even if I may never use them again) will improve my over-all knowledge.

Long story short, I’m sorry for being a bit off-the-handle earlier in my responses :frowning:

2 Likes

No problem, I know how it is, I have a ton of those too :slight_smile: I hope that you get them sorted out.

Im away from my pc right now, but it seems that the game space is indeed out of the center, try putting it on 8 on the x axis(otherwise you will have to check where is the center), perhaps the resolution of the game display
could be the problem too, try turning on maximise on play to see how it behaves? Let us know

1 Like

I just tried it, and neither appears to work sigh I’ll get back to building some levels though. I’ve been getting creative with them, but nowhere near as creative as some people have gone with their project and up and above it all!

1 Like

Tomorrow ill test it too and I will reply here if I find a solution :slight_smile:

1 Like

Just tried it, and adding the “-” does seems to work as it should. I think that either your gamespace width is different of 16 or it is out of the center

1 Like

Sounds like that makes sense…apart from the left-hand side is fine. Hmm…sorry as this is a big ask from the help you’ve given for me already, but are you able to alter the code so that you get a similar effect?

I would’ve thought if it was off centre that the left-side would also be affected. Hmm…I’ll tweek the settings and see what I get.

The center of the gamespace should be 0 in order to this code work (You can check it by using The Rect Tool to drag and snap another gameobject to the center of the gamespace to see it’s position) .

Would you mind uploading the project so I can take a look in order to see what is causing this problem? It will be my pleasure to help :slight_smile: you can send it through private mensage if you want.

I’m back with the same problem, but operating completely differently!

I’ll post below pictures, but it appears that the mirrored paddle goes off screen, until I move my mouse off screen. Bit weird and quite different to the previous problem I have on the previous build that I have built myself where-as here I took resources from the course to catch up to where I was before I lost my stuff. I’ll post the code and some screenshots of the effect, the playspace and so on.

Reverse Paddle Code:

using UnityEngine;

public class ReversePaddle : MonoBehaviour
{

// Use this for initialization
void Start()
{

}

// Update is called once per frame
void Update()
{
    MoveWithMouse();
}
void MoveWithMouse()
{
    Vector3 paddlePos = new Vector3(0.5f, transform.position.y, 0f);
    float mousePosInBlocks = Input.mousePosition.x / Screen.width * 16;
    paddlePos.x = Mathf.Clamp((mousePosInBlocks * -1), 0.5f, 15.5f);
    transform.position = paddlePos;
}
}

Effect:

Mouse Off Screen:

MMPlaySpace:


Any help will be much appreciated.

From memory, you wanted a paddle at the top and at the bottom and for the to move in the opposite direction. e.g player moves mouse to the right, bottom paddle moves to the right, top.paddle moves to the left.

Assuming the is the case, why not have one method which is responsible for calculating the position based on the mouse at that given time and then use that value twice - once normally for the bottom paddle and then reverse the value and use it for the top paddle.

You are then not reliant on where the mouse is, or rather was, and the paddles should keep in sync.

Not sure what you mean. Do you mean possibly linking to instead of the mouse position to the other paddle instead?

Exactly.

So if the bottom.paddle.moves left, the top paddle moves right. All decisions being based on the position of the first paddle.

Hmm…interesting idea…just been working a bit on that idea but struggling to create the code to find the paddle and use it in the context that’s currently there, however I get a feeling I need to re-work the code to work a different way.

Here’s what I have so far in regards to that:

using UnityEngine;

public class ReversePaddle : MonoBehaviour
{
private Paddle paddle;
void Start()
{
paddle = GameObject.FindObjectOfType();
}
void Update()
{
MoveWithMouse();
}
void MoveWithMouse()
{
Vector3 paddlePos = new Vector3(0.5f, transform.position.y, 0f);
float mousePosInBlocks = Input.paddle.x / Screen.width * 16;
paddlePos.x = Mathf.Clamp((mousePosInBlocks * -1), 0.5f, 15.5f);
transform.position = paddlePos;
}
}

Take the code you have on the bottom paddle, which you know is working 100% and moving the paddle as expected…

  • Add a variable for the top paddle
  • Find the top paddle in the Start() method and populate the variable
  • within the MoveWithMouse() calculate the position of the bottom paddle, probably easiest to store that in a temporary variable
  • assign this position to the bottom paddle
  • invert the value in the temporary variable
  • assign this position to the top paddle

Remember, they will have differing Y values that will need over riding in the position assignment.

If this works, you might consider making it a bit more generic rather than attaching to one paddle and controlling the other from it, but best to get it working first…

@Rob

Hi Rob, I’ve been re-reading over this post for the past couple of days and found that I am uncertain what is going on here. I had attempted to find the paddle in the code, however that’s about as far as I have gotten with this.

The movewithmouse command doesn’t like me adding numbers to it in any way. Do I need to add a Vector 3 of somekind?

sigh this “Simple Idea” I had it just getting more and more complicated as it goes on…think I’ll make a start with laser defender, but I’m going to keep working on this. I’m just moving on with the work so I can feel like I’m actually progressing in my learning.

Hi @Aron_Marczylo,

Can you paste up for me please your paddle script. Not the reverse one but the one which works for the main (bottom) paddle.

Also, provide for me the name of the second paddle (the top one).

I will have a proper look at thia for you this evening after my son has gone to bed (around 9.30pm UK time). :slight_smile:

Privacy & Terms