- Home /
2d Game Jump Issue
Hi Unity,
I wrote a script that allows my player to jump bu adding force in the y direction, what im trying to achieve is disabling the character from jumping a second time before it actually hits something from below (ground, box, enemy, etc).
I tried using the get ground hit but thats only for wheel colliders. Thought of using filtered collisions by tags, and that would restrict me to ground, unless i tag other objects too ( i dont mind if i have to, but) that would include if i hit a box from the bottom for example which om trying to avoid.
Any suggestions, and solutions obviously welcome
Thnx in advance
Cheers :)
Answer by sona.viswam · Mar 19, 2013 at 06:18 AM
This is the best solution for jump of character controller. Please go through it.
jumping code of character controller
Change the axis according to the need.
HTH..
Here is the web link to CharacterController.$$anonymous$$ove, @sonaviswam posted the offline documentation link in his own PC.
There was a 2D platformer project from Unity demo, with a very complete script on CharacterController. Unfortunately, the package is no longer there anymore.
Answer by prototype7 · Mar 19, 2013 at 04:30 AM
if you have CharacterController on your player you can do this
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded)
{
// do something
}
Thank you guys for your feedback.
Unfortunately its not ending there, i added a character controller and was testing if i get collisions with a debug log, and it wasnt reporting anything. I created a empty game object to try to narrow down the issue and gave it just a controller on its own, addded a gravity script to it as well, since it conflicts with a rigidbody. and my object would not collide with the floor, it would just go straight thru.
Pulled out the 1st person controller prefab, and it collided just fine, discovered that i had to have a character motor script attached to my object, also was forced to follow the same setup in hierarchy and children setup as the 1st person prefab.
Thing is my game is a 2D game and im relying on mesh colliders, adding useless scripts such is character motor is really not good coding, is there anyway around this issue, where i can simple just add a character controller and have it collide normally with the floor (as i dont really need it to do so since im still gona have to leave my mesh collider on, but that would ensure that the controller is reporting collisions).
Thnks a lot guys ,didnt expect it to become so complex so fast.
Cheers :)
Your answer
Follow this Question
Related Questions
Strange Bounce after Parenting Objects on 2D Game 0 Answers
Using Texture Assets in Code 1 Answer
A node in a childnode? 1 Answer
Problem with a button made 2 Answers
Launching Projectile Problems (2D) 0 Answers