Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Trying to follow along a tutorial, but AddForce(ForceMode2D.Impulse) doesnt work

$
0
0
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); } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>