Question by
Tomaten_Typ · Feb 25, 2020 at 09:17 PM ·
addforceforcemode
Trying to follow along a tutorial, but AddForce(ForceMode2D.Impulse) doesnt work
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<Rigidbody2D>();
}
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);
}
}
}
Comment