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]