Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TehWut · Oct 01, 2011 at 06:27 AM · charactercontrollermovecharacter.move

charactercontroller.Move Jump not working!

why won't this work? instead of pressing a button, on collison I want this enemy character controller to jump up....and be affected by gravity e.t.c . It should work, should'nt it? it sucessfully prints "afaf" once it collides.... Also I am fairly new to coding.

    var jumpspeed = 35;
 var up;
 var controller;
 var isJumping: boolean = false;
 function Update()
 {
 var controller : CharacterController = GetComponent(CharacterController);
 up = (Vector3.up);
 }
 
 function OnControllerColliderHit(hit:ControllerColliderHit)
 {
 print("atleastwerehere");
 if (hit.gameObject.tag == "Jumppad")
 {
 print("afaf");
 controller.Move(up*jumpspeed);
 }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FLASHDENMARK · Oct 01, 2011 at 07:28 AM

You are heading in the right direction, but there are some things you could improve on.

Use a variable called moveDirection

Use that to jump

Something like this:

 var jumpSpeed = 35;
 private var up = (Vector3.up);
 var controller;
 var isJumping: boolean = false;
 private var moveDirection : Vector3 = Vector3.zero; 
 
 function Update()
     {
     var controller : CharacterController = GetComponent(CharacterController);
     }
 
 function OnControllerColliderHit(hit:ControllerColliderHit)
     {
     print("atleastwerehere");
     if (hit.gameObject.tag == "Jumppad")
         {
         print("afaf");
         moveDirection.y = jumpSpeed;
     }
 }

It should look something like that. It is much better and works really good.

  • Code is untested.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Arbiter · Oct 01, 2011 at 07:41 AM 1
Share

Where it says:

private var up = (Vector3.up);

you can just delete that line of code if you want it is not used.

PS. I am OrangeLightning

avatar image TehWut · Oct 01, 2011 at 07:46 AM 0
Share

No use.....it doesn't even print the "afaf". I wonder what the issue is.... I'll work on it some tomorrow.

avatar image Arbiter · Oct 01, 2011 at 07:53 AM 1
Share

If it does not print "afaf" are you sure that you are using a CharacterController? or the gameObject is tagged "Jumppad"?

avatar image Bunny83 · Oct 01, 2011 at 12:14 PM 1
Share

ehmm, you forget to actually move the CharacterController in Update ^^

add the line:

 controller.$$anonymous$$ove(moveDirection * Time.deltaTime);

at the end of your Update function.
You also forgot to implement gravity, so you're not jumping. You're a little rocket...

avatar image Coreyf716 · Dec 08, 2012 at 11:16 PM 0
Share

Don't put character = GetComponent(CharacterController) in update. You're wasting processing power by getting the component every frame. Put it outside of a function and assign it in the inspector.

avatar image
0

Answer by TehWut · Oct 01, 2011 at 05:53 PM

Thank you all so Much!!!!

I finally got it to work, I never would have had it not been for you guys :/

Here is the final code: it may look funny but my Astar AI is pretty fickle about movements.

 var jumpSpeed = 35;
 var controller;
 var gravity = 20.00;
 var isJumping: boolean = false;
 var Jump : boolean = false;
 private var moveDirection : Vector3 = Vector3.zero; 
 
 function Update()
     {
     var controller : CharacterController = GetComponent(CharacterController);
     if (controller.isGrounded)
     {
     isJumping = false;
     }
     if (Jump)
     {
     isJumping = true;
     }
     if (isJumping)
     {
     Jump = false;
     controller.Move(moveDirection * Time.deltaTime);
     }
     moveDirection.y -= gravity * Time.deltaTime;
 }
 function OnControllerColliderHit(hit:ControllerColliderHit)
     {
     print("atleastwerehere");
     if (hit.gameObject.tag == "Jumppad")
         {
         print("afaf");
         Jump = true;
         moveDirection.y = jumpSpeed;
     }
 }

again thank you all!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Louard · Apr 06, 2012 at 09:44 PM 0
Share

I'm trying to do something similar using the default Character Controller+Character $$anonymous$$otor set up and I've got it mostly working, but here's my problem. I get a $$anonymous$$UCH bigger kick from my jump pad if I jump up when I hit it because my character motor also has upward velocity that it's applying. Likewise, if I jump down onto the jump pad, I get almost to boost at all. I'm new to coding and the $$anonymous$$otor script is strange and scary to me! How could I make it so my jump pad gives the same kick regardless of my character's current velocity?

avatar image hike1 · Jun 10, 2013 at 06:45 PM 0
Share

It's not working

NullReferenceException: Object reference not set to an instance of an object jumper.Update () (at Assets/scripts/jumper.js:12)

 if (controller.isGrounded)//line 12


I have a character motor (default fps controller prefab) would that cause the error? Am I supposed to check Jump or IsJumping?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Character controller not following moving parent transform properly 3 Answers

The character controller return null refrence 2 Answers

CharacterController moves only sometimes 2 Answers

Another question about Skyroads-like moving 0 Answers

CharacterController Gravity 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges