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 ThatOwlGuy · Jun 03, 2012 at 03:53 AM · charactercontrollercontrollervelocityread-only

Apply force to character controller?

I know that you can't really apply force to a character controller directly but can you simulate this? Velocity is read-only apparently, and I'm not sure how to produce the same effect. In my script I have a grapple ability that is basically a prefab being fired and whenever it collides, it turns kinematic and freezes in place. I want to know how to change jelly's velocity so that on collision he "hops" so far to the right on the x axis to simulate pulling on the grapple. Below is the script I currently have, but it functions only on rigidbodies.

 function OnCollisionEnter(collision : Collision) 
 {
     // when the spawned grappling hook collides with another object,  it is made kinematic, thus freezing it in place and making it appear as if it was stuck
     rigidbody.isKinematic = true;
 
     //This gets the shooter, or jelly in this case...
     jelly = GameObject.Find("jelly");
     //this makes jelly jump
     jelly.rigidbody.AddForce(250,250,0);
 
     //after force is added the now "stuck" grapple will wait for 1 and a half seconds until it destroys itself
     yield WaitForSeconds (1.5);
     Destroy (gameObject);
 }
 
 //the coordinates of the grapples object against the coordinates of jelly
 function Update()
 {
     jelly = GameObject.Find("jelly");
     //If they are at the same Y height or less than jelly, they are destroyed
     if(this.transform.position.y<=jelly.transform.position.y)
         Destroy (gameObject);
     
     //If they are greater than 10 units over the height of jelly they are destroyed
     if(this.transform.position.y>jelly.transform.position.y+10)
         Destroy (gameObject);
 }

[Edit by Berenger : Please make sure to format your code properly next time. It's the button with a bunch of 1 and 0]

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
0

Answer by Berenger · Jun 03, 2012 at 04:19 PM

You can use a rigidbody in a similar way. But if you want to push a character controller, you need to look how the jump is performed in character motor and do something similar, in an other direction.

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 ThatOwlGuy · Jun 03, 2012 at 06:52 PM 0
Share

hmmm... I tried it but I have no idea what I'm doing here. I hypothesized that I could just change the jump "command" where it tells the velocity on the y axis to change and specify that beforehand that it needs to find jelly and apply velocity to the charactercontroller but I'm just shooting in the dark here

function OnCollisionEnter(collision : Collision) {

// when the spawned grappling hook collides with another object, it is made kinematic, thus freezing it in place and making it appear as if it was stuck rigidbody.is$$anonymous$$inematic = true;

//This gets the shooter, or jelly in this case... jelly = GameObject.Find("jelly"); //this was supposed to make jelly jump jelly.charactercontroller.velocity.y = $$anonymous$$athf.$$anonymous$$in(0, velocity.y) - movement.gravity Time.deltaTime; jelly.charactercontroller.velocity.x = $$anonymous$$athf.$$anonymous$$in(0, velocity.x) Time.deltaTime;w

//after force is added the now "stuck" grapple will wait for 1 and a half seconds until it destroys itself yield WaitForSeconds (1.5); Destroy (gameObject); }

//the coordinates of the grapples object against the coordinates of jelly function Update(){ jelly = GameObject.Find("jelly"); //If they are at the same Y height or less than jelly, they are destroyed if(this.transform.position.y<=jelly.transform.position.y){ Destroy (gameObject); } //If they are greater than 10 units over the height of jelly they are destroyed if(this.transform.position.y>jelly.transform.position.y+10){ Destroy (gameObject); } }

avatar image Berenger · Jun 03, 2012 at 07:48 PM 0
Share

Take a look at that. If it doesn't help, could you add \ before your code and \<\\pre> after, for the formatting ? Also, Find( name ) is a bit slow, you should try another to get the jelly's reference. By tag or type is faster.

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

i am getting velocity when ever my player with character controller collides with a Enemy With character controller.kindly suggest me solutions. 0 Answers

What is Happening here? please help. 0 Answers

How to Rotate a Character using the mouse? [JS] 0 Answers

In-Air Movement for Custom Controller? 0 Answers

CharacterController causing characters to fly around screen 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