- Home /
Parented Rigidbody Collisions
Hello, I am doing some experiments with physical melee weapons.
I will start by describing my issue: The melee weapon I made, (a baseball bat), is moving mainly through code and parenting. This is causing some very weird behaviour of the physics engine, that can't detect collisions as I wish it could.
Anyone has suggestions on how to resolve this?
This is the code I'm using: (You can see I set the fixed delta time to a lower value, that helps a lot with collision detection)
using UnityEngine;
using System.Collections;
public class BaseballBat : MonoBehaviour {
public GameObject weaponHolder;
public Vector3 weaponHolderLoweredPos = new Vector3(0.45f, 0.075f, -0.1f);
public Vector3 weaponHolderLoweredAng = new Vector3(-13, 180, 180);
public Vector3 weaponHolderPokePos = new Vector3(0.34f, 0.36f, -0.47f);
public Vector3 weaponHolderPokeAng = new Vector3(90, -20, 0);
public VectorSpring weaponHolderPos;
public VectorSpring weaponHolderAng;
void Start(){
Time.fixedDeltaTime = 0.005f;
weaponHolderPos = new VectorSpring(weaponHolder.transform.localPosition, weaponHolderLoweredPos, 100, 0.0000001f);
weaponHolderAng = new VectorSpring(weaponHolder.transform.localEulerAngles, weaponHolderLoweredPos, 100, 0.0000001f);
}
void Update () {
if (Input.GetButton("Fire3")){
weaponHolderPos.target_state = weaponHolderPokePos;
weaponHolderAng.target_state = weaponHolderPokeAng;
}
else{
weaponHolderPos.target_state = weaponHolderLoweredPos;
weaponHolderAng.target_state = weaponHolderLoweredAng;
}
weaponHolderPos.Update();
weaponHolderAng.Update();
weaponHolder.transform.localPosition = weaponHolderPos.state;
weaponHolder.transform.localEulerAngles = weaponHolderAng.state;
}
}
I can't really explain what's exactly going on through words, so I will leave you a build (Windows 32bit) of what I've done so far.
https://www.dropbox.com/sh/ww4hev1qijpb42j/zQRMHTi4y5
Controls: Middle mouse button to raise the baseball bat, move the mouse around to push the cubes off the table in front of you.
Notes: There is no exit button, if you fullscreen you will either have to alt-tab, or use the task manager.
There also is a cube that bounces constantly, ignore it please.
Your answer
Follow this Question
Related Questions
Character Controller meets Rigidbody 1 Answer
How to get collisions on Character controller? 1 Answer
Rigidbody.MovePosition/MoveRotation Hits far away colliders 2 Answers
Is there a solution to when colliders bypass? 2 Answers
CharacterController jumps when colliding with kinematic rigidbodies 1 Answer