- Home /
Question by
Beluga_thebloodhound · Feb 02 at 05:59 AM ·
2d game
addForce 2d
I am currently going through the Ruby2D tutorial. I am a bit confused about how to bounce the character Ruby away from the obstacles that she runs into. the code is as follow but it does not really work,
private void OnTriggerEnter2D(Collider2D collision)
{
RubyController rubyController = collision.GetComponent<RubyController>();
if (rubyController != null)
{
Rigidbody2D rubyRB = rubyController.GetComponent<Rigidbody2D>();
rubyController.addHealth(-1);
Debug.Log("Current Health" + rubyController.health);
rubyRB.AddForce((transform.position - rubyController.transform.position).normalized * force, ForceMode2D.Impulse);
}
}
can anyone suggest why and give some hints to solve it? THX!
Comment
Your answer
Follow this Question
Related Questions
Enemies in top down shooter being affected by physics of bullet 1 Answer
How can i spawn and Despawn for a specific time using this script? 2 Answers
How do I make it so that a gameobject can not be moved by the player? 2 Answers
check if position is empty before spawn 1 Answer
Aceleration 2D 0 Answers