How do I make pull object script out of this?
below is my push script.
public float pushPower= 2.0f;
void OnControllerColliderHit (ControllerColliderHit hit)
{
Rigidbody body = hit.collider.attachedRigidbody;
if (body == null || body.isKinematic)
return;
if (hit.moveDirection.y < -0.3f)
return;
if(hit.collider != null && hit.collider.gameObject.tag == "PullThis" && Input.GetKeyDown(KeyCode.E))
{
Vector3 pushDir = new Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
body.velocity = pushDir * pushPower;
}
}
At first I thought, all I have to do is press some key and then do exactly the other way of pushing by inserting "-" in Vector 3 x and z, which didn't work. I've been following other tutorials and answers as well, but still can't figure out.
Also, there's another tutorial I'm following for pulling object but that's for 2D game. I've been trying to convert into 3D components as much as I can but I hit the wall with
Physics2D.queriesStartInColliders = false;
Is there something like that checks rays/lines without arguments(no Linecast) in Physics? (or ways to check).
So, if you guys can help me with: #1. example of codes based on push script or #2. similar ways to check rays/lines like Physics2D.queriesStartInColliders = false;
It'd be much appreciated.
Thanks for help in advance.
Answer by VaygrEmpire · Feb 20, 2017 at 12:06 PM
I figured this out by modifying pick up scripts I got from tutorials and freezing rotations on rigidbody. It...actually works!
Your answer
Follow this Question
Related Questions
Bullet spawning at high Player speed 1 Answer
Forge-like in game editor 0 Answers
Pick Up Rigidbody with mouse 0 Answers
A fast question about player physics (Unity 5, C#) 0 Answers