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

Player appears to teleport instead of adding force

$
0
0
I tried to add a simple jumping mechanic, The player does seem "jump", But instead of going up smoothly it just teleports up, Here's the code, Any help is appreciated. public class PlayerMovement : MonoBehaviour { public Rigidbody2D RigidBody; Vector2 Movement; public float Speed = 10f; public Animator Anim; public float JumpForce; public bool IsGrounded; public Transform GroundCheck; public float CheckRadius; public LayerMask Ground; void Start() { RigidBody = GetComponent(); } void Update() { Movement.x = Input.GetAxisRaw("Horizontal"); Anim.SetFloat("Horizontal", Movement.x); Anim.SetFloat("Speed", Movement.sqrMagnitude); if (Movement.x > 0) { transform.localScale = new Vector2 (10.0f, 10.0f); } else if (Movement.x < 0) { transform.localScale = new Vector2 (-10.0f, 10.0f); } if (Input.GetButtonDown("Jump") && IsGrounded == true) { RigidBody.AddForce(transform.up * Time.deltaTime * JumpForce); //Here is the thing. } } void FixedUpdate() { IsGrounded = Physics2D.OverlapCircle(GroundCheck.position, CheckRadius, Ground); RigidBody.MovePosition(RigidBody.position + Movement * Speed * Time.fixedDeltaTime); if (Input.GetButtonDown("Jump") && IsGrounded == true) { RigidBody.AddForce(transform.up * JumpForce); } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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