Moving left to right and after the level ends move character right to left
So im making an endless runner game where the character runs left to right at the start of the level. After the player gets done with that level, the next level they run from right to left. How would I go about creating a Player Controller Script? Also Im using unity3d.
Here is what I got so far
public float moveSpeed; // Character's spped
public float jumpForce; // Character's jump
public float dashDelay; // Delay in the dash sequence before you can dash again
public float dashDistance; // How far you can dash
private Rigidbody myRigidbody; // The RigidBody that is made for the PlayerObject
// Use this for initialization
void Start () {
myRigidbody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
myRigidbody.velocity = new Vector2(moveSpeed,myRigidbody.velocity.y);
if(Input.GetMouseButtonDown(0)) // if the left mouse button is pressed (or in this case the left side of screen) the character will jump in the air
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
}
if(Input.GetMouseButtonDown(1))
{
}
}
}
Answer by jstnwlls · May 21, 2018 at 07:24 PM
Nvm i figured it it out. I basically changed this line of code
myRigidbody.velocity = new Vector2(moveSpeed,myRigidbody.velocity.y);
to this
myRigidbody.velocity = transform.right Time.deltaTime moveSpeed;
It worked perfectly at least for now lol
Your answer
Follow this Question
Related Questions
MoveTowards is curving for no reason 0 Answers
having CharacterController movement in fixedupdate causes jerky movement on camera 0 Answers
Bug on Character movement 0 Answers
How to make character look at movement direction? 1 Answer
First person movement with character controller does not detect ground properly 0 Answers