- Home /
How to get correct collision when picking up objects and moving them at high speeds near walls?
I made a script that I attached to the First person controller that allows me to pick up objects, rotate and thrown them similar to amnesia the dark decent.Collisions work to an extent but the problem is, when I pick up and swing an object fast enough near a wall it will go straight through.
Here's how I'm moving the object:
ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
newPos = ray.GetPoint(objectToPlayerDistance);
Vector3 velocityDirection = (newPos - pickedObjectTransform.position) / Time.deltaTime;
pickedObjectrigBody.velocity = velocityDirection;
The only other thing I've done to the rigid body is make the freezeRotation boolean true. I have noticed that the velocity stays at (0, 0, 0) when I'm holding an object. Could that be a contributing factor? I'm at a loss and have spent a good while trying to figure this out. Thanks in advance.
Actually I didn't really understand your situation (probably because I just woke up), but I guess moving your code from "Update" to "FixedUpdate" might solve the problem.
The code is already in fixed update. Sorry I should have specified.
why don't you child the object to your character, so it will move together?
@malachite I want to the same but ive checking for code on how to it
Answer by EBR · Aug 28, 2013 at 10:06 PM
I think you are looking for this (http://wiki.unity3d.com/index.php?title=DontGoThroughThings) :)
Unfortunately it didn't work :/
I made a small video showing my problem. Slow collisions work fine but when holding an object and turning towards a wall the object goes straight through. Could this be a result of the way im moving the object?
Have you checked that the collision detection modes of your colliders are set according to this ?
Collision detection mode for the object that I picked up is set to continuous dynamic but I don't know about the wall. I'll check when when I get home. Otherwise I guess ray casting is the best route to take.
I know, I'm late to this, but I have same problem right now.. Have you solved this issue?