[SOLVED] Camera bobbing up and down

Hello!

In this script I need help with a cool camera motion to add some style to my game and make it more appealing to the player.

I want to make it so when W or A or S or D is pressed the camera will move up then back down to its original position. This action will repeat until W or A or S or D is released.

Hi @Mason_Rocchio! You can do this easily with translateLocal in the update function. Move the camera up to a certain value and move it back down to a certain value.

I was thinking of that, I was just unsure how to do it.

What kind of game are you making?

A horror game in the woods

You want to make it look like your player is walking on an uneven surface? If that’s the case I think it’s better to move your player entity a little bit up and down.

The camera moves up then down to make it look like a running animation. The surface is flat.

Basically the same. Just give it a try and share your result when you get stuck.

Ok i know how to get it to move up but not down would it be this?

if(this.app.keyboard.ispressed(pc.KEY_W)){
this.entity.translatelocal(0,2,0);
this.entity.translatelocal(0,-2,0);
else{
if(this.app.keyboard.wasreleased(pc>KEY_W)){
this.entity.setlocalposition(0,0,0);

that’s what I think it is.

I think something like below.

if (this.app.keyboard.isPressed(pc.KEY_W)) {
    if (this.entity.getPosition().y < 0.5) {
        this.entity.translateLocal(0, 1, 0);
    }
    else {
        this.entity.translateLocal(0, -1 ,0);
    }
}

Could I do something like

this.app.systems.rigidbody.applyforce(0,25,0);

Yes.

if (this.app.keyboard.isPressed(pc.KEY_W)) {
    if (this.entity.getPosition().y < 0.5) {
        this.entity.rigidbody.applyForce(0, 25, 0);
    }
    else {
        this.entity.rigidbody.applyForce(0, -25, 0);
    }
}

it says this.app.keyboard.ispressed is not a function

Yes, can you pay a little more attention to correct capitalization yourself please? I take over your code and don’t check every letter every time myself. It’s isPressed and not ispressed.

the script is in the player

It wont work

the player wont bob up and down

Maybe the player position is already higher then 0.5 by default.

it is so do I update it in the script to be higher?

Yes, give it a try.