first person collider

so im new to unity and have a bit of experience and i made a first perosn script.
the script itself works but when i touch somthing the screen is vibrating.

video:

is there someon that knows how i can prevent this ?

Post your code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class movescript : MonoBehaviour {

    public float speed = 10.0F;

    // Use this for initialization
    void Start () {
        Cursor.lockState = CursorLockMode.Locked;
    }
   
    // Update is called once per frame
    void Update () {

        float horizontal =  Input.GetAxis("Horizontal") * speed;
        float vertical = Input.GetAxis("Vertical") * speed;

        horizontal *= Time.deltaTime;
        vertical *= Time.deltaTime;

        transform.Translate(horizontal, 0, vertical);

        if (Input.GetKeyDown("escape"))
        {

            Cursor.lockState = CursorLockMode.None ;

        }

    }
}

Just in case you didn’t know there is a first person controller as an asset (standard asset). If you want to try making your own, nothing wrong with that.
Okay, I believe the issue you are facing is because you have a physics rigidbody and you are moving the cube by translate/setting its position directly (instead of using force/velocity in the physics engine).

dou know how i can fix that

Well, you can :
A) use the controller in the standard assets.
B) move the cube with velocity and/or addforce. (I"d say velocity for normal/smooth movements and force for … like jumping/other burst-like stuff, as an example).

There are probably other options, but those 2 seem the simplest.

ok thx i wil try b becous i dont wannna use assets

Just to be clear, when you say you don’t want to use assets, is that because you want to program it on your own, or you don’t want to pay for something? The ‘standard assets’ are free, come with Unity/by Unity… if that was your concern, I mean.

i want to program my own

Okay :slight_smile:

I respect that. I , too, wanted to program my own (though, for me it was 3rd person).

Try the velocity thing for movement, to begin with and see how you like it.
For velocity, you need only set it to the speed you want (ie: no need for time.deltaTime)
You can do rb.velocity = 10; and that’s that. (where rb is GetComponent() cached).

and if no input is detected , you’d set it to 0 and/or let drag slow it down for you.

Hopefully that’s a good start.

Well, just to be clear, it’d be rb.velocity = new Vector3(10,0,0); since velocity is a Vector3. (This example would make it move rightwards at 10 units per second.)

Thank-you! Yes. :slight_smile: