playMaker

Author Topic: Rigidbody goes through wall/terrain  (Read 218 times)

SawyerK

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Rigidbody goes through wall/terrain
« on: January 19, 2020, 09:54:12 AM »
When i pick up a rigidbody (parenting to playercamera) i turn its gravity off and get its localposition then write it back every frame with setPosition to keep it in the parented position.I don't use isKinematic. The problem is the object still goes through walls and terrain. They have collision.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4710
    • View Profile
    • jinxtergames
Re: Rigidbody goes through wall/terrain
« Reply #1 on: January 19, 2020, 11:09:09 AM »
Hi.
i am not sure what you mean, but when you disable gravity on a object its bets to do a set velocity right after you set gravity to 0

can you show a video or some images?

SawyerK

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Re: Rigidbody goes through wall/terrain
« Reply #2 on: January 19, 2020, 05:02:59 PM »
Sure. I do use setVelocity and setAngularVelocity, both set to 0 and i use getPosition and setPosition so the object stays in front of the camera, it looks like that the picked up object collides with the wall/ground when it touches it but it still goes through. :D




« Last Edit: January 19, 2020, 05:06:24 PM by SawyerK »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4710
    • View Profile
    • jinxtergames
Re: Rigidbody goes through wall/terrain
« Reply #3 on: January 20, 2020, 01:57:55 AM »
Hi,
I did i quick google search and this might get you in the right direction :

https://answers.unity.com/questions/1195454/rotating-gameobject-not-colliding-1.html

SawyerK

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Re: Rigidbody goes through wall/terrain
« Reply #4 on: January 20, 2020, 06:13:53 AM »
Thanks, but it still goes through even if i use angularVelocity to rotate, i think the problem going to be the setPosition, but i dont know how to set the objects position withouth setPosition.

SawyerK

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Re: Rigidbody goes through wall/terrain
« Reply #5 on: January 20, 2020, 06:32:08 AM »
I tried using moveTowards which works for bigger objects, but even that's not perfect smaller object like a handgun goes through wall/ground.

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 138
    • View Profile
Re: Rigidbody goes through wall/terrain
« Reply #6 on: January 20, 2020, 06:54:03 AM »
Since it's physics, make sure you're using Rigidbody set position.

SawyerK

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Re: Rigidbody goes through wall/terrain
« Reply #7 on: January 20, 2020, 07:52:40 AM »
The rigidbody setPosition doesn't have a self "Space" it only uses world space.

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 138
    • View Profile
Re: Rigidbody goes through wall/terrain
« Reply #8 on: January 21, 2020, 03:16:23 AM »
If you want accurate physics emulation(which seems like your problem from initial post) you should use Rigidbody.

SawyerK

  • Playmaker Newbie
  • *
  • Posts: 13
    • View Profile
Re: Rigidbody goes through wall/terrain
« Reply #9 on: January 21, 2020, 07:10:49 AM »
It is a rigidbody.

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 138
    • View Profile
Re: Rigidbody goes through wall/terrain
« Reply #10 on: January 21, 2020, 09:53:54 AM »
I mean Rigidbody actions. This is the absolute first thing I would try considering using transform position doesn't use physics and can lead to things like colliders going through colliders.