I’m working on a (I hate to use this term) 2.5D platformer game, so the player only moves on the x and y planes but i have a pendulum hammer that swings on the z and when the pendulum makes contact with the player it goes through the player or just stops dead untill the player has passed depending on what method i use to propell the pendulum.
1-> How do i make sure the pendulum always swings with the same force/momentum/speed.
2-> how do i allow the player to be turned over to physics when its been hit by the 2 “hammer faces” (i’m thinking triggers parented to the hammer)
3-> Restore the players controlls after respawn. (because it is so far apparent i will have to dissable/remove them in step 2)
any ideas?
You can use a hinge joint on the hammer to make sure it can only rotate in the right axis at the right point. The hinge joint has a motor property that can be used to rotate the object around the joint. You can change the direction of the motor torque periodically to get the pendulum to swing back and forth regularly.
To make the character respond to physics when hit, add a rigidbody component to it, but enable its isKinematic setting. You can detect when the hammer hits something with its OnCollisionEnter function. When a collision is detected, you can set the isKinematic flag of the hit object to false, giving it physical behaviour:-
function OnCollisionEnter(coll: Collision) {
coll.rigidbody.isKinematic = true;
}
Then, when the character respawns, set its isKinematic to false again to remove the physics.