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

Can't add AddForce or velocity to RigidBody2D

$
0
0
Hello everyone, I'm trying to get the player knockback when touching an enemy. Everything works fine, but when I try to apply force to the player nothing happens. Does anyone know what the problem might be? Here is the code: private void Start() { Debug.Log(currentHealth); rb = GetComponent(); playerMovement = GetComponent(); currentHealth = health; player = GameObject.Find("Player"); } private void Update() { if(rb.velocity.y < 0) { CheckAttackHitBox(); } Debug.Log(currentHealth); if(rb.velocity.y >= 0 && playerStompedEnemy == false) { PlayerTouchEnemy(); } if(touchDamageTime <= 0) { knockBack = false; } if(stompTime <=0) { playerStompedEnemy = false; } } private void PlayerTouchEnemy() { enemyDetected = Physics2D.OverlapBox(playerPos.position, sizeOfBox, angle, whatIsDamageable); touchDamageTime -=Time.deltaTime; if(enemyDetected != null && touchDamageTime <= 0 ) { attackDetails.damageAmount = attack1Damage; attackDetails.stunDamageAmount = stunAmount; gameObject.transform.SendMessage("Damage", attackDetails); rb.AddForce(knockBackDirection); knockBack = true; touchDamageTime = 1.5f; } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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