- Home /
How to make Poltergeist like behavior in unity?
I am making a horror game about ghosts like poltergeists and I cannot figure out how to make objects through themselves at the player, shatter, doors swing open and closed and earthquake like phenomenon. There is always the add force to rigid body script but how would I change that to work like I have said? I am mainly using java script for my project but any would help alot.
-Edit- I already have a script that can make a rigid body to fly up and or effect near by rigid body's but I cannot figre out how to make it throw itself towards or at the player.
var radius = 5.0; var power = 10.0; function Start () { // Applies an explosion force to all nearby rigidbodies var explosionPos : Vector3 = transform.position; var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
for (var hit : Collider in colliders) {
if (hit && hit.rigidbody)
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0);
}
}
Answer by Tehnique · Jul 21, 2014 at 11:44 AM
Please write separate/more detailed questions. Such general-scope questions as yours are better suited for the forums. Anyway, I'll give you a few general ideas.
Throw objects: AddForce with direction as Vector3 from object to camera.
Shatter: No built-in function, but you can animate a shatter state for your objects. Here are some other ideas: Tutorial , Asset.
Door Swing: HingeJoint, use the motor property to open/close/slam/whatever.
If you want to use "AddExplosiveForce", you have to calculate exactly where to place the explosion in order to get the object to "throw itself" at the player. However, this is a VERY bad approach for what you want to do, AddForce is the normal approach.
ah I see, thank you for explaining that. I do not know how to make it add force to the object to send it towards the player though because I am abit new to JavaScript. Is it possible I could have another example link or something to work off more?