I have tried everything, and it definitly has to do something with ForceMode.Impulse, because
a) the Condition triggers,
b) ForceMode2D.Force works.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Playero : MonoBehaviour{
public float runSpeed;
private Rigidbody2D myPlayer;
private Vector3 change;
public bool isGrounded = false;
public bool isGrounded2 = false;
void Start () {
myPlayer = GetComponent();
}
void Update () {
change = Vector3.zero;
change.x = Input.GetAxisRaw("Horizontal") * runSpeed;
}
void FixedUpdate (){
Jump();
myPlayer.MovePosition(
transform.position + change * runSpeed * Time.fixedDeltaTime
);
}
void Jump(){
if (Input.GetButtonDown("Jump") && isGrounded == true){
myPlayer.AddForce(new Vector2(0f, 500f), ForceMode2D.Impulse);
}
}
}
↧