So im programming a player in my survival horror game and i want the camera od the player to move up and down everytime he takes a step. I already have the if statement and i dont know how to move a gameobject up and down
if (Input.GetKey(“W”))
{
Camera.Find. what do i do here?
}
Sounds like you need a ‘Camera Bob’ or ‘Head Bobber’ script. There are quite a few videos, text tutorials and scripts online.
Here’s an example script from Nathan Hyde
thanks for the headbobber, but now my player doesn’t move. Here’s the movement script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public Rigidbody rb;
[SerializeField] public float speed;
public void Start()
{
rb = GetComponent<Rigidbody>();
}
public void FixedUpdate()
{
Move();
}
public void Move()
{
float hAxis = Input.GetAxisRaw("Horizontal");
float vAxis = Input.GetAxisRaw("Vertical");
Vector3 movement = new Vector3(hAxis, 0, vAxis) * speed * Time.fixedDeltaTime;
Vector3 newPostiton = rb.position + rb.transform.TransformDirection(movement);
rb.MovePosition(newPostiton);
}
public void Update()
{
if (Input.GetKey("e"))
{
speed = 25;
}
speed = 18;
}
}