Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 leonalchemist · Apr 18, 2012 at 09:41 PM · addforcecharactermotor

Adding force to character on CharacterMotor

Basically since im using the PlatformInputController i dont wanna use a rigidbody otherwise t'll mess up the physics so im wondering how would i go about adding force to the my character towards a certain direction. Im trying to understand how the CharacterMotor.js works but dont understand it that much.

(trying to do a wall jump btw, i want to add force to the oppsite direction to the wall im facing)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by T27M · Apr 19, 2012 at 12:12 AM

This may help, but I'm not sure if it would accomplish what you needed. One of the functions of the CharacterMotor.js is SetVelocity. You can change this by passing it a variable.

The function in the CharacterMotor.js..

 function SetVelocity (velocity : Vector3) {
     grounded = false;
     movement.velocity = velocity;
     movement.frameVelocity = Vector3.zero;
     SendMessage("OnExternalVelocity", SendMessageOptions.DontRequireReceiver);
 }
 
 A script I use to respawn a player which passing a varaible to the function above.

 function playerRespawn ()
 {
     // Variable : ScriptName
     var setVelocity : CharacterMotor;
     // Sets a velocity, this would be not moving at all.
     var myNewVelocity = Vector3(0,0,0);
     
     // Gets the script that is attached to the same object. 
     setVelocity = gameObject.GetComponent("CharacterMotor");
     // Passes in the new velocity
     setVelocity.SetVelocity(myNewVelocity);

     // Moves the player to the spawn point.

You probably wont need this part

     transform.position = Vector3(256,5,256);
     
     
 }

This works for what I needed, you might want to check the api for GetComponent.

Comment
Add comment · Show 6 · 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 leonalchemist · Apr 19, 2012 at 01:04 AM 0
Share

thx a bunch, lot of help on this one; like i said i was trying to do a wall jump system and it works well except that it only happens only some of the time; im thinking is because i have too many if statement im trying to make it happen in one frame but im not sure

 function OnTriggerStay (hit : Collider)
 {
 if((hit.gameObject.tag == "LeftWall") && (Input.Get$$anonymous$$ey("d")))
 {
     grounded = true;
     
     if (Input.GetButtonDown ("Jump"))
     {
         myNewVelocity = Vector3(-18,8,0);
         setVelocity.SetVelocity(myNewVelocity);
     }
 }

}

here's my piece of code i added in as example maybe u can spot something im not doing right?

avatar image T27M · Apr 19, 2012 at 01:21 PM 1
Share

The API says that OnTriggerStay is called "almost" every frame. I would assume that is why sometimes it works and sometimes it doesn't, not 100% sure on this one.

$$anonymous$$aybe you could try and use OnCollisionStay ins$$anonymous$$d which is called every frame.

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionStay.html

avatar image leonalchemist · Apr 19, 2012 at 01:28 PM 0
Share

nvm, got everything fixed :)

avatar image leonalchemist · Apr 20, 2012 at 01:30 AM 0
Share

Question.. when im doing something basic like this, why isnt it working? noob :3

 function OnCollisionStay(hit : Collision)
 {    
     if(hit.collider.tag == "ABC") //I've tried 'hit.gameObject.tag' as well
     {
         Debug.Log("I am colliding");
     }
 }
avatar image T27M · Apr 20, 2012 at 03:18 PM 0
Share

I think it's todo with the character controller not having an actual rigidbody attached.

You could try this

 function OnControllerColliderHit(hit : ControllerColliderHit) {
     if(hit.collider.CompareTag("ABC"))
     {
                 // Changes the color of material, not needed.
         hit.collider.renderer.material.color = Color.red;
         Debug.Log("I am colliding");
     }
     
 }
Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

rigidbody2d.addforce for is not working for the x axis 0 Answers

Kick a Ball - Add Force? 2 Answers

AddForce in multiplayer displays as curved motion 1 Answer

Getting launch angle for projectile given height, distance and speed in 3D 2 Answers

Add Force if GameObject is detected in a Polygon Collider 2D 1 Answer


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