Problem with Making an "Angry Birds" style game - Part 1 using Unity V5.5.1f1

Hello, i’m new to the community so I wasn’t sure if this was the right place to post this. Sorry if it is not.

I have been following this tutorial on making an angrybirds like game and i noticed it is designed for a previous version. Although I was able to adapt some of my code to the new version, the end result was rather disappointing… There are some sections of the code that just wont work, particularly the section that destroys the spring to release the projectile. Here are some of the problems I had:

1-Projectile wont launch
In the tutorial the tutor wrote this code line:
(…)
if (!Rigidbody2D.IsKnematic && prevVelocity.sqrMagnitude > GetComponent().velocity.sqrMagnitude)
{
Destroy(spring);
}
(…)
However since now the Kinematic option of the RigidBiddy2D component is not a boolean this comparison isnt possible, even using the code adaptation:
(…)
if (!RigidbodyType2D.Knematic && prevVelocity.sqrMagnitude > GetComponent().velocity.sqrMagnitude)
{
Destroy(spring);
}
(…)

2-The Back Rubber band wont set properly
The rubber bands should update using the code
(…)
Vector2 catapultToProjectile = transform.position - catapultLineFront.transform.position;
leftCatapultToProjectile.direction = catapultToProjectile;
Vector3 holdPoint = leftCatapultToProjectile.GetPoint(catapultToProjectile.magnitude + circleRadius);
catapultLineFront.SetPosition(1, holdPoint);
catapultLineBack.SetPosition(1, holdPoint);
(…)

But the console gives the message “LineRenderer.SetPosition index out of bounds!” and only the back rubber band wont set. Since the index is 1 for both i don’t understand my error.

sorry again if this is not the correct place to post this. If anyone wants to help i would be glad to send my code and some screenshots, I would appreciate anyone that can help translate this code to the new version of the engine.

Please use code tags, your post is barely readable. I haven’t tried the project, so I’m not sure if this works, but here are my guesses.

  1. This is simply a coding error. ‘RigidbodyType2D.Kinematic’ is not a specific RigidBody2D, but just the type. You need to compare the actual component:
Rigidbody2D rb2d;
if (rb2d.bodyType != RigidbodyType2D.Kinematic)
  1. Probably forgot to add the positions to the LineRenderer component? You need to enter ‘2’ for the size variable. Then you have element 0 and element 1 - you’re probably getting out of bounds because element 1 doesn’t exist by default.
1 Like

I figured it out early today, but that was the exact problem. Had some other issues, but now the launching part is fine.
Thanks for your help friend