I created a new game type for my block breaker where there is a second paddle at the top, but the idea is that is moves inverted compared to your paddle to make this particular game mode difficult. However, despite my initial thoughts, attempting to get this to work is not very easy.
I could’ve simply made it a double-paddle, but I wanted to be a bit more daring and now I’m back on the forums asking for help as no one appears to have found a solution for this very problem.
I copy and pasted part of the code from the other paddle, thinking I’d just need to find an easy way to tinker with the x position, but I’ve yet to find a way that makes it work and not shoving it into either the right or left collider.
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, 0.5f, 15.5f);
transform.position = paddlePos;
}
}
update:
Thought I would give everyone a picture as to what exactly I’m trying to accomplish with this. The first picture below is what I get when I load the game up and want to remain the same. Both paddles in the centre, facing each-other.
When I move to one side, I want the second paddle at the top to move in an opposite direction so it’s inverted to where my mouse moves as demonstraited below in a terrible editing job in Pain shows you, maybe moving it further so it avoids the score like shown below.
I’ve tried to look up many ways how to do this and a common suggestion seems to be you have to find out what the location for the centre is. I hope someone is able to come up with a solution for this problem I’m having with what to code and how to code it.
that doesn’t appear to work and I’ve tried placing the -1 everywhere, but it doesn’t appear to work or the paddle ends up shooting off into the right side (pushing against the collider) or to the left side of the screen and that’s where I’ve been stuck.
Untested, but figured the multiplication of -1 on the mousePosInBlocks should give you the opposite…
Still not fully firing here I’m afraid, but I figured;
1 * -1 = -1, 2 * -1 = -2
which gives you the opposite of
1, 2 etc…
Of course, looking at it now, I can see that this would create negative numbers which are less than the lowest value of your clamp - hence, the forced to the left… the above might work with a central origin.
So, how about taking the calculated value away from half of the boundary limit also?
Actually I added an “-( xxx)”,
you have to make sure that the center of the game space is the origin (0,0,0), perhaps this is why this gap is appearing
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
No problem, I know how it is, I have a ton of those too 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
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!
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
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 you can send it through private mensage if you want.