- Home /
Ground stops working and ball stops jumping
Hello there! I started learning Unity a few hours ago, fallowing some tutorials on the internet. I have made a very simple platform game, where a ball jumps from platform to platform by pressing W and moving with A and D. Very basic.
Eventhough, it looks like i made something wrong, cause I have 2 problems that show up.
1: sometimes the W (jump) doesnt work. In other words, when I want to jump from platform A to platform B and press W to do so, the ball won't react to it and just keep rolling. The funny thing is though that this only happens sometimes. Sometimes it works, sometimes it doesn't. I don't know why.
2: This one is pretty annoying. For some reason there is a limit to my level space: when I put a platform (the same as all the others, since I just copy the object) overpassing a limit in the map, the ground function stops working and the ball just falls through the object. It has something to do with the map, since I have moved the object to the side and then I can stand on one half but when I pass that certain point I just fall. I really don't know what the problem is.
I don't know if I made myself clear, maybe I should copy the script.
Anyway! Thanks in advance,
Here is the ball scrips (the ground has no scrips since it's a normal cube):
#pragma strict
var rotationspeed = 100;
var jumpheight = 8;
private var isfalling = false;
function Update ()
{
//Handle ball rotation.
var rotation : float = Input.GetAxis ("Horizontal") * rotationspeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);
if (Input.GetKeyDown(KeyCode.W) && isfalling == false)
{
rigidbody.velocity.y = jumpheight;
}
isfalling = true;
}
function OnCollisionStay ()
{
isfalling = false;
}
Can't say for sure but check your colliders are where you expect them to be. If it suddenly drops through the floor then that implies a gape in colliders.
Could be the colliders are offset or could be a section of floor that the collider got deleted from.
Hm, How can I check that? It is strange though, cause i just copy the same object and the other work. And what about the jumping thing?
You really are new :¬)
Highlight item in the Hierarchy one at a time and look in the scene, you should get a green line round the edge that represents the collider. Also look in the inspector for any that don't have a collider at all, or any that have become triggers. Triggers are colliders that allow something to pass through them.
Finally you really want to click on Learn at the top of this page and do a load of the tutorials on there.
So, checked the Collider, all seems to work. Don't know what the problem was.
Do you know something about my jump problem?
Is there a specific order you would recomend me to do the tutorials? Should I do the 4 games there and then move on with other stuff?
Answer by Mmmpies · Feb 07, 2015 at 05:48 PM
The only thing I can think is that your isFalling bool is not set correctly. A good tip for debugging is run without MaximizeOnPlay set on the Game window. That way you can highlight the object with the script on it in the hierarchy and look in the inspector, you might have to make isFalling public to see it, not sure about JS.
As for tutorials, what works best for you is the way go go.
Sorry for any typo's, on my pbone!
Your answer
Follow this Question
Related Questions
Platform Effector 2D (one-way) not working 0 Answers
Weird 2d platform problem 0 Answers
yeild WaitForSeconds Bugged 1 Answer
How can I stop the edges between my vertex-snapped cubes flickering? 0 Answers
2D 360 degress platformer example needed 0 Answers