2D platformer tutorial – HELP

Updated on January 6, 2018 in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on January 6, 2018

Hello,

I have been following the 2D Platformer tutorial on the youtube channel (brackeys) but… since i am new to programming, i installed unity 2017… This made some problems for the “robot” character because his default movement scripts and physics were all errors. So I went on another unity tutorial and it told me to do this… There is an error!!! The game runs (well, not really a game), but my character doesnt move when I press the buttons! (Error: NullReferenceException)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerPlatformerController : PhysicsObject
{

public float maxSpeed = 7;
public float jumpTakeOffSpeed = 7;

private SpriteRenderer spriteRenderer;
private Animator animator;

// Use this for initialization
void Awake()
{
spriteRenderer = GetComponent<SpriteRenderer>();
animator = GetComponent<Animator>();
}

protected override void ComputeVelocity()
{
Vector2 move = Vector2.zero;

move.x = Input.GetAxis(“Horizontal”);

if (Input.GetButtonDown(“Jump”) && grounded)
{
velocity.y = jumpTakeOffSpeed;
}
else if (Input.GetButtonUp(“Jump”))
{
if (velocity.y > 0)
{
velocity.y = velocity.y * 0.5f;
}
}

bool flipSprite = (spriteRenderer.flipX ? (move.x > 0.01f) : (move.x < 0.01f));
if (flipSprite)
{
spriteRenderer.flipX = !spriteRenderer.flipX;
}

animator.SetBool(“grounded”, grounded);
animator.SetFloat(“velocityX”, Mathf.Abs(velocity.x) / maxSpeed);

targetVelocity = move * maxSpeed;
}
}

  • Liked by
Reply
1 on January 6, 2018

What version of Unity were you using before because, unless you use Unity 4 or older, you’ll have to change a lot from what he types. The video is pretty outdated. Later on in the video he switched to Unity 5 which is modern so that stuff is up to date. Just read the comments to fix errors and search this forum. You can also ask me for help. I’ll take a look at my code tomorrow to see what is different from yours and let you know what needs fixed. Good luck.

on January 6, 2018

Also what are the errors you are trying? What do the say? And what lines are the errors on? Just paste the error codes exactly.

Show more replies
  • Liked by
Reply
Cancel