How do I apply force to a rigidbody to make them go flying into the air upwards. rigidbody.AddForce (Vector3.up * 15); doesn’t seem to be working for me. Thanks appreciated…
a force of 15 is not a lot, depending on the mass.
You want to expose a force variable so you can tune it in the inspector. You then multiply by this force variable instead of 15.
I thought of that too. To make sure that it wasn’t just not enough force I set it to multiply by 90 and still nothing happened.
Try with a real force like 1000.
If that doesn’t do anything your addforce function call is probably never called, since you don’t say from where you are calling addforce, it’s not really possible to say why. But an easy way to test is by simply adding a print(“Adding force”); just before the call to rigidbody.AddForce.
I’ll try that much force, but other things are being called at the same time, like the Spring Pad Sound Effect, so I assume that the addforce is being called too.
EDIT: Still nothing with the 1000 force.
Maybe your object is otherwise constrained. A collider blocking it. A joint holding it back.
Is the rigidbody kinematic?
Yeah, it’s Kinematic. Still don’t know what the problem is.
Well. The purpose of kinematic rigidbodies is that they are not affected by physics. (Forces, collision detection, joints) So if you want to apply a force, then your rigidbody can not be kinematic.
http://unity3d.com/Documentation/Components/class-Rigidbody.html
Well, it didn’t used to be Kinematic. I misunderstood and made it kinematic when you asked me if it was. So It is not kinematic.
Are you sure you are referencing the right rigidbody and everything? It might help to post your script.
Although it is generally less fluid and can cause problems, you could do this:
player.rigidbody.velocity.y += jumpPower;
My script is as follows:
function OnTriggerEnter (other : Collider) {
if (other.name == "Sonic") {
audio.Play();
other.rigidbody.AddForce (Vector3.up * 1000, ForceMode.Acceleration);
}
}
Should I not be using an OnTriggerEnter? It’s really the best kind of collision that I know how to do.
So is one reason left why this could happen.
Another script is resetting the velocity every frame. Possibly your sonic controller script is doing some weird things.
You can test this theory, by making a simple cube, naming it Sonic, placing it above the trigger, adding a rigidbody, and letting it fall through the trigger in playmode. That should push it up. If it does, then you know, that your sonic controller does something which causes the force to be removed. Eg. setting the velocity from code every frame or using an extremely high drag value.
The cube went flying. So what do I do to Sonic. I’m just using the Character Controller script from the Goober example.
Aha.
Well the charactercontroller doesn’t use and can not use a rigidbody.
It’s a special controller that that is inherently unphysical.
Take a look at the sample script how jumping (using a key) is implemented there. You have to perform the same operations on the script if you want to implement a jumppad.
Okay, but how do I make it do that stuff to the character. I can’t get this. I’ve tried everything I could think of.
which script are you using? i couldn’t find a cc script. just the fps walker etc. did you try something like this? (untested and i haven’t scripted much)
var jumpSpeed = 8.0;
var padTrigger = false;
var jumpBoost = 5.0;
if (Input.GetButton ("Jump")) {
if (padTrigger = true){
jumpSpeed = jumpSpeed * jumpBoost;
padTrigger = false;
}
moveDirection.y = jumpSpeed;
}
I’m using the script from the Animation Test example in the Goober scene.
Try the following:
- On you jumppad, make sure there is a rigidbody and a collider. If you are using OnTriggerEnter, set the collder is set to be a trigger.
- Add an empty game object to your goober, sonic, or whatever it is.
- Add a collider to this empty game object. Set the collider to be a trigger. Adjust it to the appropriate size and make sure it is then.
- Move the empty game object with the collider so that it is below your character.
I do not know all the affects of the above, but it makes the OnTriggerEnter fire for me on the goober example.
think i found it… this one? SuperMarioController.js
barely took a glance but…
as ifrog says make the trigger fire. make that toggle a boolean var called fired.
in the controller script…
var fired = false
var jumpboost = 5
var jumpSpeed = 8
in the jump code
fired = true
verticalSpeed = jumpSpeed * jumpboost;
fired = false
verticalSpeed = jumpSpeed;
[edit: this only jumps if the player hits jump. now that i think about it, sonic jump pads launched you if you just ran into them didn’t they? is that what you’re after?]
[edit 2; clarified (hopefully) after ifrog’s next comment…]
I have not really looked to much at the character controller script, but probably the easiest thing to do is to just have the trigger script set a variable in the character controller script. In the existing update loop add a check for that variable and if set, then trigger the jump (with boost if you like) just like you would if the “jump” key was pressed. At least that way all the movement of the character would be kept centralized.