- Home /
Parenting a rigid body with gravity
Hi Guys
I've got the following script attached to my crate object, and I've managed to get pulling to work, however I want the gravity to continue working too, without the object falling through the floor.
I know I can set the object to not use gravity but this will only work if the ground is flat, so the object 'floating' wouldn't be visible, however on non flat ground it will be obvious so this is why I require the physics to remain on.
I've tried many things but I'm still unsure on the best method, I've seen a few similar questions so my method is a combination of those, all suggesting 'parenting' the crate to the player.
My script is below:
var box : Transform; //a box we'll use an a example
var player : Transform; //our player
var body : Rigidbody = hit.collider.attachedRigidbody;
function OnCollisionEnter(coll: Collision) {
if(Input.GetButton("Fire1"))
body.isKinematic) { return; }
{
box.parent = player;
}
//box.parent = null;
}
}
Another small question, I'm unsure if its a big enough question to warrant a separate thread is, 'How can I check if my player should push or pull an object', I have some objects the player only push and others that are pushable & pullable, I'm unsure how I would set it so that I can pull only if I'm facing the box and press in the opposite direction, as now the player just switches direction. (if that should be another thread please let me know and I shall edit this).
Thankyou in advance.
Your answer
Follow this Question
Related Questions
Another Gravity Question: Player suddenly flies upward 1 Answer
How to get Ray rotation from direction 0 Answers
iOS game: Physics with ConstantForce 1 Answer
PlayerMove script affecting gravity. 0 Answers
Gravity within range 1 Answer