- Home /
Collision between kinematic and dynamic rigidbodys
hello i am having problems with on collision enter between 2 objects one object has a kinematic rigidbody and another has a dynamic rigidbody. it wont detect collisions. they both have box collider 2d but for some reason wont work. Please help.
Here is my code;
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class AIAttack : MonoBehaviour { public int damageOnCollison = -10;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
PlayerStatus playerStatus = collision.gameObject.GetComponent<PlayerStatus>();
playerStatus.AdjustHealth(damageOnCollison);
}
}
}
Take a look at this description from the Unity Scripting API:
https://docs.unity3d.com/ScriptReference/Rigidbody-is$$anonymous$$inematic.html
“Controls whether physics affects the rigidbody.
If is$$anonymous$$inematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. The rigidbody will be under full control of animation or script control by changing transform.position.”
A normal rigidbody is a physics driven body where a kinematic rigidbody is not.
Answer by CalvinXAnime · Jul 11, 2020 at 03:29 PM
You can use OnTrigger instead since kinematic and kinematic does not activate collision.
Your answer
Follow this Question
Related Questions
How to move multiple dynamic gameobjects with one moving platform which is controlled by the player 0 Answers
How to perform grasp action on a cloth? 3 Answers
How do I prevent a Kinematic Rigidbody2D from moving a Dynamic Rigidbody2D on Collision? 1 Answer
Stopping objects with colliding with similar objects. 1 Answer
Making the collider change after being instantiate 2 Answers