Struggling with bounce pad in platformer game.

I have recently started experimenting with a custom character controller while following a tutorial and I am loving it so far. I have stumbled upon an issue where I can’t get a bounce pad working correctly and I cant figure out why. Any help would be appreciated.

There is an error saying “Operator ‘+’ cannot be applied to operands of type ‘float’ and ‘Vector3’” on the line saying “player.moveDirection.y = player.moveDirection.y + (transform.up * bouncePower);”.

public class BouncePad : MonoBehaviour {

PlayerController player;
public float bouncePower;

// Use this for initialization
void Awake()
{
    player = GameObject.Find("Player").GetComponent<PlayerController>();
}

void OnTriggerEnter(Collider mycollision)
{
    if (mycollision.gameObject.tag == "Player")
    {
        print("Bounce");
        player.moveDirection.y = 0f;
        player.moveDirection.y = player.moveDirection.y + (transform.up * bouncePower);
    }
}

firstly if your going to write

player.moveDirection.y = player.moveDirection.y +

you should just write.

player.moveDirection.y += 

though i assume this is kind of temporary code.

I mean saying player.moveDirection.y = 0f;
then immediatly saying it equals something else, but also adding to it.

I mean this should really just be

 if (mycollision.gameObject.tag == "Player")
 {
     print("Bounce");
     player.moveDirection.y = transform.up * bouncePower;
 }

that is the exact same code.

I can tell you it’s saying your trying to add a single number and a vector (which is a collection of three numbers) together and basically it doesn’t know which of the three numbers in the vector you want the single number added to.

I’d need to see the data type for bounce power but i’m guessing that at some point it says

Vector3 bouncePower;

in your code and your trying to take a part of a vector, it’s Y value and add it to it.

you could try multiplying which is probably what you want instead of adding, but you still have the issue of

player.movedirection.y = transform.up * bouncePower

because just imagine for example bouncePower which is a x,y,z and its x = 1, y = 2, z =3;
let’s assume transform.up equals 0,1,0 because that’s global up and whatever. it’s y of 1, zero everythign else.
your trying to say

player.movedirection.y = transform.up(0,1,0) * bouncePower(1,2,3) 

so we can multiple two vectors and thats fine but what you end up with is

player.movedirection.y = (0,2,0) and that doesn’t make sense because Y is a single number, it can’t make sense of you assinging it three different numbers.

now if bouncePower is just an int. we’ve still got a problem because again, transform.up is a vector.

so 0,1,0 times say 2 is

0,2,0 but then we have

player.movedirection.y = 0,2,0 

and were back where we started. all that is to explain the error so that you can realize why it’s wrong and not just have me fix it.

to fix it.

player.moveDirection.y is a single number, you can’t have vectors in it, at least not all three parts, you can try.

player.movedirection.y = (transform.up * bouncePower).y; 

that will probably work, but i can’t be positive without seeing all the code.