|
How can i make my script driven player and ai character interact with rigidbodys. So the player can push away boxes.
(comments are locked)
|
|
The built-in CharacterController class has special status in the physics engine which means that it doesn't interact with other physics objects by default. In order to be able to push objects around, you need to add a script, as described in the CharacterController class manual page. It gives this example: I'm also interested in this for future reference, how do you make it so they can only push certain objects, is that simply by naming a specific game object and if so what would that script look like... sorry, new to this whole scripting thing too. ;)
Feb 13 '11 at 01:05 AM
Michael 12
(comments are locked)
|
|
I use a modified version of the example. It's more useful if you want to interact via physics, I personally think my solution makes more sense. This solution will apply force to the point of contact. This means that if you bump into the corner, the object will rotate, if you hit the top, it will tip over. It's by no means absolutely perfect but it is better and still very simple. The one also works with up and down so if you ever wanted to use a teeter totter you could. If you tried to simply enable downwards movement on the original script you won't get the intended results. I put this right into the CharacterMotor script which Unity provides, it really works nicely and makes things fun. Nice ! What is your variable movement ? "Unknown identifier: 'movement'."
Nov 12 '12 at 10:15 AM
anthonyk2
I could be wrong but I believe it's in the default CharacterMotor script. If it's not use a number like "20" (my value) or "10" (the default) instead of "movement.Gravity".
Nov 12 '12 at 08:21 PM
titegtnodI
(comments are locked)
|
|
Wont rconise "moveChar" Assets/trampoline test.js(24,29): BCE0005: Unknown identifier: 'moveChar'.
(comments are locked)
|
|
I've recently come up with a funky solution to a similar problem: I had to go through a revolving door, pushing the blades of the door with my CharacterController. The revolving door was done with a (very very low poly) mesh collider and a RigidBody component held in place by a vertical hinge joint. After I found out that a CharacterController isn't able to influence RigidBodies I created a new CapsuleCollider with the same size like the one my CharacterController used, attached a RigidBody component to it and wrote a very little script that always places this new CapsuleCollider at the same position that my CharacterController currently occupies. - That way the Capsule was pushing the doors like it would be pushed by the CharacterController itself. I then added a few lines of code to my script to switch off all physics on the CapsuleCollider at a certain distance from the door so that I could save the calculations for the physics when not needed. That's probably not a good solution at all, but it worked perfectly and without any noticeable negative effect.
(comments are locked)
|
1 2 next page »
