Is there a way to see if the Y axis is going up

Im making a mobile game for the first time and making movement. I want to see if there is some code that can see if the Y axis of the mouse position is going up or down. And if it is going up it moves the character up. I also want to do the same for X axis so is this possible?

1 Answer

1

If what you need is to move the character, then you can use this code inside of the Update() function in a - preferably movement or controller - script attached to your character:

private float speed = 4f;
private Vector3 velocity = Vector3.zero;
private RigidBody rigidBody;

void Update() {
    // ...
    Vector3 forward = transform.forward * Input.GetAxis("Vertical");
    Vector3 right = transform.right * Input.GetAxis("Horizontal");
    velocity = (forward + right).normalized * speed;
    // do the actual movement in FixedUpdate()
}

void FixedUpdate() {
    transform.position += velocity * Time.fixedDeltaTime;
    // or you can set the velocity on the RigidBody, and let Physics do the movement:
    // rigidbody.velocity = velocity;
}

I don't understand what that code is. I know how to make pc movement. Im looking for mobile movement. I don't want any plungins though.

Sorry, my bad. Didn't understand your question. Saw "mouse" so I immediately thought "PC". Maybe you're asking about touches? // Vector2 result. handling first touch var movementDelta = Input.GetTouch(0).deltaPosition; var upPixels = movementDelta.x; // negative if down var rightPixels = movementDelta.y; // negative if left more info: [Unity Scripting API - Input.GetTouch][1] [1]: https://docs.unity3d.com/ScriptReference/Input.GetTouch.html