Parkour Game

Started by
18 comments, last by Gian-Reto 7 years, 10 months ago

We have ran into an issue with the game. We made that script but it teleports you and does not make you fly there. We need your help now to help fix this. We are adding a download link to the game. Please realize that this game is protected under copyright. If you find the fix or a way to make it work better let me know. Also here is some info you will need.

Inside the scripts folder is the script we used.

Inside of the actual 1x1 JumpPad, it has an object called Jumppad in it. That is tagged with the jumpPad tag. Found in the player stats code. That is the secret behind it all of it.

Also, there is a bit of broken code in there. Thank you if you decide to help me.

Here is the download (FIXED)

Advertisement

It's pretty late right now, so I don't have time to look at this in depth, but I can at least fix your broken code and explain why it's wrong. I remember what it's like starting out :).

So, first I'll explain what's wrong.

Your broken code:


function OnTriggerStay (col : Collider) {
	if(col.gameObject.tag=="jumpPad") {
	
		Debug.Log("HOVER");
		
		this.transform.position.y =+5;
		this.transform.position.x =+3;
	}
}

Basically, your syntax is just wrong. You have =+ instead of +=. That's it.

Paste this into your code and it will work:


function OnTriggerStay (col : Collider) {
	if(col.gameObject.tag=="jumpPad") {
	
		Debug.Log("HOVER");
		
		this.transform.position.y += 5;
		this.transform.position.x += 3;
	}
}

Next, I would change OnTriggerStay to OnTriggerEnter. OnTriggerStay will execute as long as the player is within the trigger. This might work in some cases, but in others, it might cause it to execute multiple times.

OnTriggerEnter will only execute once, when you enter the trigger.

So, now your code isn't broken. However, I don't think this approach will work very well. You're using Unity's standard character controller, which deals with physics and rigidbodies, as others have said. You're directly manipulating the object's position, which the physics and rigidbody are also manipulating behind the scenes, so you're effectively fighting the physics engine.

I would strongly recommend you use Rigidbody.AddForce(), as others have suggested. Look into it and try to figure it out. That's the best way to learn. Don't give up though, I remember when I first started--it's not easy.

Also, if you want a good place to practice javascript (and programming in general): codecademy.com is great for beginners.

And once you get comfortable with that, I would consider switching over to C# for Unity, eventually. Take that with a grain of salt though. It's just my opinion.

It's pretty late right now, so I don't have time to look at this in depth, but I can at least fix your broken code and explain why it's wrong. I remember what it's like starting out :).

So, first I'll explain what's wrong.

Your broken code:


function OnTriggerStay (col : Collider) {
	if(col.gameObject.tag=="jumpPad") {
	
		Debug.Log("HOVER");
		
		this.transform.position.y =+5;
		this.transform.position.x =+3;
	}
}

Basically, your syntax is just wrong. You have =+ instead of +=. That's it.

Paste this into your code and it will work:


function OnTriggerStay (col : Collider) {
	if(col.gameObject.tag=="jumpPad") {
	
		Debug.Log("HOVER");
		
		this.transform.position.y += 5;
		this.transform.position.x += 3;
	}
}

Next, I would change OnTriggerStay to OnTriggerEnter. OnTriggerStay will execute as long as the player is within the trigger. This might work in some cases, but in others, it might cause it to execute multiple times.

OnTriggerEnter will only execute once, when you enter the trigger.

So, now your code isn't broken. However, I don't think this approach will work very well. You're using Unity's standard character controller, which deals with physics and rigidbodies, as others have said. You're directly manipulating the object's position, which the physics and rigidbody are also manipulating behind the scenes, so you're effectively fighting the physics engine.

I would strongly recommend you use Rigidbody.AddForce(), as others have suggested. Look into it and try to figure it out. That's the best way to learn. Don't give up though, I remember when I first started--it's not easy.

Also, if you want a good place to practice javascript (and programming in general): codecademy.com is great for beginners.

And once you get comfortable with that, I would consider switching over to C# for Unity, eventually. Take that with a grain of salt though. It's just my opinion.

Thank you so so so much. Now the game is no longer halted and is almost done with its prealpha stage

It's pretty late right now, so I don't have time to look at this in depth, but I can at least fix your broken code and explain why it's wrong. I remember what it's like starting out :).

So, first I'll explain what's wrong.

Your broken code:


function OnTriggerStay (col : Collider) {
	if(col.gameObject.tag=="jumpPad") {
	
		Debug.Log("HOVER");
		
		this.transform.position.y =+5;
		this.transform.position.x =+3;
	}
}

Basically, your syntax is just wrong. You have =+ instead of +=. That's it.

Paste this into your code and it will work:


function OnTriggerStay (col : Collider) {
	if(col.gameObject.tag=="jumpPad") {
	
		Debug.Log("HOVER");
		
		this.transform.position.y += 5;
		this.transform.position.x += 3;
	}
}

Next, I would change OnTriggerStay to OnTriggerEnter. OnTriggerStay will execute as long as the player is within the trigger. This might work in some cases, but in others, it might cause it to execute multiple times.

OnTriggerEnter will only execute once, when you enter the trigger.

So, now your code isn't broken. However, I don't think this approach will work very well. You're using Unity's standard character controller, which deals with physics and rigidbodies, as others have said. You're directly manipulating the object's position, which the physics and rigidbody are also manipulating behind the scenes, so you're effectively fighting the physics engine.

I would strongly recommend you use Rigidbody.AddForce(), as others have suggested. Look into it and try to figure it out. That's the best way to learn. Don't give up though, I remember when I first started--it's not easy.

Also, if you want a good place to practice javascript (and programming in general): codecademy.com is great for beginners.

And once you get comfortable with that, I would consider switching over to C# for Unity, eventually. Take that with a grain of salt though. It's just my opinion.

I want to use C# the issue is the tutorial used it and the other guy confused me. I mean i can try to use the code he gave me. Also it says i need an instance of the unity rigidbody I am so sorry but what does in mean by that.

It's pretty late right now, so I don't have time to look at this in depth, but I can at least fix your broken code and explain why it's wrong. I remember what it's like starting out :).

So, first I'll explain what's wrong.

Your broken code:


function OnTriggerStay (col : Collider) {
	if(col.gameObject.tag=="jumpPad") {
	
		Debug.Log("HOVER");
		
		this.transform.position.y =+5;
		this.transform.position.x =+3;
	}
}

Basically, your syntax is just wrong. You have =+ instead of +=. That's it.

Paste this into your code and it will work:


function OnTriggerStay (col : Collider) {
	if(col.gameObject.tag=="jumpPad") {
	
		Debug.Log("HOVER");
		
		this.transform.position.y += 5;
		this.transform.position.x += 3;
	}
}

Next, I would change OnTriggerStay to OnTriggerEnter. OnTriggerStay will execute as long as the player is within the trigger. This might work in some cases, but in others, it might cause it to execute multiple times.

OnTriggerEnter will only execute once, when you enter the trigger.

So, now your code isn't broken. However, I don't think this approach will work very well. You're using Unity's standard character controller, which deals with physics and rigidbodies, as others have said. You're directly manipulating the object's position, which the physics and rigidbody are also manipulating behind the scenes, so you're effectively fighting the physics engine.

I would strongly recommend you use Rigidbody.AddForce(), as others have suggested. Look into it and try to figure it out. That's the best way to learn. Don't give up though, I remember when I first started--it's not easy.

Also, if you want a good place to practice javascript (and programming in general): codecademy.com is great for beginners.

And once you get comfortable with that, I would consider switching over to C# for Unity, eventually. Take that with a grain of salt though. It's just my opinion.

I want to use C# the issue is the tutorial used it and the other guy confused me. I mean i can try to use the code he gave me. Also it says i need an instance of the unity rigidbody I am so sorry but what does in mean by that.

And it did not work.

This is not going to directly answer your question, but I feel I should offer some advice (not trying to be preachy, just helpful):

It sounds to me like you're very new to coding (no offense, we all were at some point :)). This is going to make things difficult for you during your game development unless you either team up with a programmer, or get serious about learning the programming and other game development stuff yourself.

I don't know how old you are, but if you're serious about game development, I would very seriously consider studying something game development related in college or university (3D modelling, programming, etc., or even a Game Development course itself). You don't need a formal education to become a game developer by any means (practice and experience are the most important things), but a formal education definitely won't hurt. At the very least, it will give you something to put on a resume (which could get you in the door at a studio), show you the areas you should be studying (game development is a huge umbrella under which many subjects fall), and give you access to knowledgeable people who can help you hone your skills.

The most frustrating thing for me when I began trying to learn programming/game development was figuring out exactly what I should be studying. There are a ton of very specific areas that would be useful to know as a game developer (animation, art creation, programming, art theory, game theory, UI Design, etc., etc), and even more places to learn those skills. Trying to focus your learning and trying to find a good resource are extremely difficult.

I think you've made a good choice in using Unity to start with game development. The community is great, the documentation is awesome, there are a billion tutorials, a bunch of free assets and it's free. Not only that, but many many top-notch studios use/have used Unity at some point. It's a great skill to have.

So, I'm going to give you some resources that I think will help:

  1. Ask questions and look for answers at Unity Answers (be specific in your questions, and provide the code you're having trouble with, if it's a coding question)
  2. Subscribe to the mailing list for Unity Certification Training - I have no idea how much it costs, but it should be released very soon, and will undoubtedly be a good resource
  3. Do the Official Unity Tutorials - There are a bunch of complete games to work through, as well as videos on smaller topics
  4. Make frequent visits to the Unity Manual/Documentation - They're always adding new features to Unity. I've been using it for nearly 4 years and I'm still finding things I didn't know existed (hint: do a search for Rigidbodies in the manual)
  5. Check out Unity's Live Training Sessions
  6. Even though this is the last on the list, I have to highly recommend it, especially for a beginner: Ben Tristem's Unity Course on Udemy - It's regularly around $60, but I've linked to a discounted offer for %40 off until June 18th. There's a very active community, the instructor is also active in answering questions, and it has a ton of varied projects included in the course. There are over 50 hours of content, so it's very much worth the price. It won't teach you everything, but it will give you a great overview of Unity's interface and features, and it covers a lot of programming as well. And it's fun! You won't be a pro after completing this course, but I really think it's the best resource I've seen to get started for beginners. After completing it you'll be able to make some decent games, and you'll have a better idea of what to learn next.

Sorry I didn't explain what a rigidbody is. One of the most important skills to have as a developer is the ability to find solutions. Asking questions is one great way to do that, but every answer you can find on your own should be considered a victory. See if you can figure out the rigidbody thing using the manual.

If you still can't figure it out, let me know and I'll see if I can help.

Seriously consider taking that course. It'll make your life easier.

I want to use C# the issue is the tutorial used it and the other guy confused me. I mean i can try to use the code he gave me. Also it says i need an instance of the unity rigidbody I am so sorry but what does in mean by that.

If you mean me by "the other guy", I gave you an example using the physics engine. Which means it will ONLY work if the characters have a rigidbody and collider attached to them. That is why I included a link to the Unity physics documentation.

As long as you want to use the physics engine, you should really read into how to use it first. (which, given you write a game that needs physics, I highly advise, unless you either a) are bound by limitations of the target device to use as little CPU as possible (physics calculations can be heavy on the CPU), or b) have some very specific physics behaviour you want to go for that PhysX cannot support).

In TL;DR fashion, just add a capsule collider and a rigidbody component to your character and you are set.

I want to use C# the issue is the tutorial used it and the other guy confused me. I mean i can try to use the code he gave me. Also it says i need an instance of the unity rigidbody I am so sorry but what does in mean by that.

If you mean me by "the other guy", I gave you an example using the physics engine. Which means it will ONLY work if the characters have a rigidbody and collider attached to them. That is why I included a link to the Unity physics documentation.

As long as you want to use the physics engine, you should really read into how to use it first. (which, given you write a game that needs physics, I highly advise, unless you either a) are bound by limitations of the target device to use as little CPU as possible (physics calculations can be heavy on the CPU), or b) have some very specific physics behaviour you want to go for that PhysX cannot support).

In TL;DR fashion, just add a capsule collider and a rigidbody component to your character and you are set.

I have that all in the character. It just won't let me run the game due to the error and i want to bypass it because it will cause no issues in the game.

This is not going to directly answer your question, but I feel I should offer some advice (not trying to be preachy, just helpful):

It sounds to me like you're very new to coding (no offense, we all were at some point :)). This is going to make things difficult for you during your game development unless you either team up with a programmer, or get serious about learning the programming and other game development stuff yourself.

I don't know how old you are, but if you're serious about game development, I would very seriously consider studying something game development related in college or university (3D modelling, programming, etc., or even a Game Development course itself). You don't need a formal education to become a game developer by any means (practice and experience are the most important things), but a formal education definitely won't hurt. At the very least, it will give you something to put on a resume (which could get you in the door at a studio), show you the areas you should be studying (game development is a huge umbrella under which many subjects fall), and give you access to knowledgeable people who can help you hone your skills.

The most frustrating thing for me when I began trying to learn programming/game development was figuring out exactly what I should be studying. There are a ton of very specific areas that would be useful to know as a game developer (animation, art creation, programming, art theory, game theory, UI Design, etc., etc), and even more places to learn those skills. Trying to focus your learning and trying to find a good resource are extremely difficult.

I think you've made a good choice in using Unity to start with game development. The community is great, the documentation is awesome, there are a billion tutorials, a bunch of free assets and it's free. Not only that, but many many top-notch studios use/have used Unity at some point. It's a great skill to have.

So, I'm going to give you some resources that I think will help:

  1. Ask questions and look for answers at Unity Answers (be specific in your questions, and provide the code you're having trouble with, if it's a coding question)
  2. Subscribe to the mailing list for Unity Certification Training - I have no idea how much it costs, but it should be released very soon, and will undoubtedly be a good resource
  3. Do the Official Unity Tutorials - There are a bunch of complete games to work through, as well as videos on smaller topics
  4. Make frequent visits to the Unity Manual/Documentation - They're always adding new features to Unity. I've been using it for nearly 4 years and I'm still finding things I didn't know existed (hint: do a search for Rigidbodies in the manual)
  5. Check out Unity's Live Training Sessions
  6. Even though this is the last on the list, I have to highly recommend it, especially for a beginner: Ben Tristem's Unity Course on Udemy - It's regularly around $60, but I've linked to a discounted offer for %40 off until June 18th. There's a very active community, the instructor is also active in answering questions, and it has a ton of varied projects included in the course. There are over 50 hours of content, so it's very much worth the price. It won't teach you everything, but it will give you a great overview of Unity's interface and features, and it covers a lot of programming as well. And it's fun! You won't be a pro after completing this course, but I really think it's the best resource I've seen to get started for beginners. After completing it you'll be able to make some decent games, and you'll have a better idea of what to learn next.

Sorry I didn't explain what a rigidbody is. One of the most important skills to have as a developer is the ability to find solutions. Asking questions is one great way to do that, but every answer you can find on your own should be considered a victory. See if you can figure out the rigidbody thing using the manual.

If you still can't figure it out, let me know and I'll see if I can help.

Seriously consider taking that course. It'll make your life easier.

Thank you so so so much it is such a great help. And i will be doing the course I have been looking for one like that for years and also thanks for the cupon code

I have that all in the character. It just won't let me run the game due to the error and i want to bypass it because it will cause no issues in the game.

Okay... can you give us

1) the exact error message Unity prints out

2) a more exact description of your character setup in the Unity editor

Reading my code again, did you check that the rigidbody and the collider component are on the same gameObject? If they are not, that would explain the error, as the code I gave you blindly assumes that they are on the same gameObject. If they are not, and there is a reason for that, fear not, we can come up with a different way of accessing the rigidbody from the collider.

This topic is closed to new replies.

Advertisement