2D platformer tutorial – HELP

Updated on March 13, 2018 in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 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
0 on February 11, 2018

You should just stick to using Brackeys’ 2D Platformer videos to make this project because it won’t work to combine tutorials. There are a lot of errors you are going to have to fix. You’ll have to search this forum and the comments on the videos to find answers, or ask me to fix the errors since they are out of date. If you’re a beginner I would suggest starting with Brackeys’ “How to Make a Game in Unity” tutorial. Good luck. Ask me if you need help.

  • Liked by
Reply
Cancel
0 on March 13, 2018

If you have a video to show and script files – would be much easier. Baiscally as I think you jsut messed up with script and adding force on some key-commands. When you press buttons – it’s adding force into different directions. This is not working in your script.

 

  • Liked by
Reply
Cancel