Notifications
bg
JI
Jon Izen
Artist
0
Likes
0
Followers
0
Connections
All
Articles1
Games5
Showcases0
Column6
Jobs0
I am getting this error for my PlayerController script:
NullReferenceException: Object reference not set to an instance of an object
PlayerController.Update () (at Assets/Scripts/PlayerController.cs:44)

My code is below. Any help would be awesome!

public class PlayerController : MonoBehaviour
{
private float horizontalInput;
private float verticalInput;
public float speed = 5;
public float borderX;
public float borderY;
private Rigidbody2D playerRb;
void Start()
{

}

// Update is called once per frame
void Update()
{


if (transform.position.x < -borderX)
{
transform.position = new Vector2(-borderX, transform.position.y);
}
if (transform.position.x > borderX)
{
transform.position = new Vector2(borderX, transform.position.y);
}

if (transform.position.y < -borderY)
{
transform.position = new Vector2(transform.position.x, -borderY);
}
if (transform.position.y > borderY)
{
transform.position = new Vector2(transform.position.x, borderY);
}

// Moves the Player
horizontalInput = Input.GetAxis("Horizontal");
playerRb.AddForce(Vector2.right * horizontalInput * speed);
verticalInput = Input.GetAxis("Vertical");
playerRb.AddForce(Vector2.up * verticalInput * speed);

N
11 days ago
You need to assign the rigidbody2d at start. Void Start () { playerRb = GetComponent<Rigidbody2D>(); }
JI
Jon Izen
May 9, 2020
Pickle Pickle Apple
PPA
View Challenge
Here is my game, "Pickle Pickle Apple" In this game, you play as a bear and try to collect fruit in the correct order. https://connect.unity.com/mg/other/pickle-pickle-apple

JI
Jon Izen
published the webgl
May 8, 2020
Pickle Pickle Apple
When this game is complete the flying bear will need to gather the flying food in the order "PICKLE, PICKLE, APPLE" to gain points. Lives will be deducted if the floating food is gathered in any other order. Lives will added by drinking the milkshake.
Hey all - Not sure if this is a reasonable request, but we have hit a brick wall over here. My son (13) and I have been trying to make a 2d game. We have had some help form the moderators, but still can't figure out why our code that should destroy objects when they collide is not working. This is the link to the project. If possible can you take a look at it to see if you can figure it out. Past that we may default to a 3d game to reference some code we reviewed in this course. Thanks very much!!! https://drive.google.com/open?id=1ls23rBeozMyB3ZXZfSfAhOS_oWmL6OFZ

b
25 days ago
No problem. One thing I forgot to put in the comments is make sure all the objects that you want to collide with each other have the same Position Z value. I all ready set them in the unitypackage keep that in mind if you add more stuff.
JI
25 days ago
Reply@benji229Here you go I left comments where I mad changes. https://drive.google.com/open?id=1r8CxE8yJONwMvyCagvbOEMj-R8ekmxNh
benji229 - thanks SOOOO much!!! Seriously appreciate your time and help!!
b
25 days ago
Let me know if you have any question.
b
25 days ago
Here you go I left comments where I mad changes. https://drive.google.com/open?id=1r8CxE8yJONwMvyCagvbOEMj-R8ekmxNh
Hi - I am trying to create my first 2d game for the Create with Code series. In my game I am trying to destroy fruit when they touch a flying bear. The fruit do not have trigger enabled and a rigidbody and they are not being destroyed. My code is attached. Any help is greatly appreciated

JI
a month ago
Reply@Jon CrowderI am a beginner but willing to look.
Thanks. I am a MAJOR beginner!! :) Here is the link and thanks for trying to help out!! Much appreciated! https://drive.google.com/open?id=1ls23rBeozMyB3ZXZfSfAhOS_oWmL6OFZ
a month ago
I am a beginner but willing to look.
JI
a month ago
Reply@Jon Crowderattach the following script to the bear, make sure the tag on the fruit you are using as a projectile is tagged Fruit. Both fruit and bear need colliders, the bear collider should be marked as a trigger. This way when the fruit enters the bears trigger, it will see if it is fruit and if it is will destroy it. I think that may do it: -----------------------------------------------------
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Fruit")) { Destroy(other.gameObject); } }
Hi Jon - I tried what you suggested but still did not work :( Any chance I can send you a link to the full project and you could take a quick look??? Thanks.
JI
a month ago
Reply@Jon Crowderattach the following script to the bear, make sure the tag on the fruit you are using as a projectile is tagged Fruit. Both fruit and bear need colliders, the bear collider should be marked as a trigger. This way when the fruit enters the bears trigger, it will see if it is fruit and if it is will destroy it. I think that may do it: -----------------------------------------------------
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Fruit")) { Destroy(other.gameObject); } }
Sorry, but it didn't work.
View More Comments
About Me
No description
See more
Skills
No skills added yet
Certifications (0)
Import
See all
Jon Izen's liked projects (14)
Following (3)
Followers (0)
No followers
Following Companies (0)
Not following anyone yet