I am attempting to complete the Tutorial for “Create with Code” Lesson 3.3 Don’t Just Stand There. Step 6 Set up a Falling Animation I’m having problems with the code where it is referencing “other” but it appears it was never defined so I’m getting compile errors. I’m new to all of this but determined to learn.
I am also having problems with the reference to the variable jumpFoce it shows in the video example the playerRb.AddForce(Vector3.up * 10 jumpForce, ForceMode.Impulse); but this creates errors as well so I removed the “10” and the errors went away is this correct?
Here is my code for the PlayerController.cs
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour { private Rigidbody playerRb; private Animator playerAnim; public float jumpForce = 10; public float gravityModifier; public bool isOnGround = true; public bool gameOver = false;
As a beginner it is important to pay attention to syntax, misspelling, case, and completeness. Each error tells you the offending script and line number. You could have easily gone back and compared that line with the original in the tutorial. Debugging doesn’t get any easier that that.
Ok, thank you so much.
I did compare my code with the code example in the video and it does not have the second “*” after 10 so I used the example, but obviously I missed something.
Ok I’m not sure which tags would be appropriate but I will try and find something that it will recognize.
I’m still having a problem with the reference to the “other” variable thats not assigned. I pasted the code in the post with descriptive comments. What would be a more appropriate way of posting this so that it is not incomplete?
I gave the code that is in the PlayerController.cs script that I am having problems with I thought that is what was needed. I’m new to all of this so please excuse my ignorance but I’m willing to learn so I can do things the right way.
I see that my code was not provided with the original post I’m not sure how to fix this. Do I start another post and just try it again?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody playerRb;
private Animator playerAnim;
public float jumpForce = 10;
public float gravityModifier;
public bool isOnGround = true;
public bool gameOver = false;
// Start is called before the first frame update
void Start()
{
playerRb = GetComponent();
playerAnim = GetComponent();
Physics.gravity *= gravityModifier;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isOnGround)
{
// The Traing Video Code shows this line with a “10” before jumpForce
// whenever I try and add the “10” i get compile errors
playerRb.AddForce(Vector3.up * 10 * jumpForce, ForceMode.Impulse);
isOnGround = false;
playerAnim.SetTrigger(“Jump_trig”);
{
}
}
}
// here is the first new reference to “other” this is where I am not sure how
// to fix this since it appears that the reference is invalid how do I fix this?
private void OnCollisionEnter(Collision collision other)
{
if (other.gameObject.CompareTag(“Ground”))
{
isOnGround = true;
} else if (other.gameObject.CompareTag(“Obstacle”))
{
Debug.Log(“Game Over Woody”);
gameOver = true;
playerAnim.SetBool(“Death_b”, true);
playerAnim.SetInteger(“DeathType_int”, 1);
}
}
}
I hope that this is the right thing to do. I just pasted the code into the post so hopefully you can see it and help me with it.
Ok I found some information in the Getting started post on the forum. Thank you anyway.
It’s so much it’s just gonna take some time and not getting overwhelmed with all thats involved. I truly need to learn all of this so that I can code my game idea. I really appreciate your patience and wisdom.