Search Unity

How to activate trigger collider based on speedxForce of an object?

Discussion in 'Scripting' started by BokuDev, Mar 3, 2016.

  1. BokuDev

    BokuDev

    Joined:
    Jan 2, 2014
    Posts:
    81
    HI I'm working on a VR title called Dream Knights,

    https://twitter.com/TheeWhiteReaper/status/704097098413772800

    I can't figure how to activate an objects collider from not being a trigger, to turning into a trigger depending on how fast that object is moving, and the force of that movement.

    I'm trying to implement great sword play (and it makes sense to at least me) to have the sword have a box collider that is able to knock into objects and push them out of the way, but the sword isn't able to do damage until the player swings the hand controller with a certain speed and force enough to activate the trigger.

    How can I accomplish speed and force tracking with C#?
     
  2. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    Is your sword moved with forces through a rigidbody?
    If it is, its simply getting the object velocity through OnTriggerEnter.

    Will be helpful to know how you are moving the sword as of now.
     
  3. BokuDev

    BokuDev

    Joined:
    Jan 2, 2014
    Posts:
    81
    The sword's rigidbody is set to Kinematic, since the sword is actually a child of the steam hand controller. Would it be possible for me to make a script that will track the speed and force of the sword child object instead of the steam controller? Valve code is wrapped in a bunch of undocumented fluff.
     
  4. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    I'd imagine you'd still be able to track the difference in position between a frame, and use that value divided by a defined limit, although the values might be minuscule. If its more than 1 then some value of scaled damage is dealt to whatever trigger the sword passed.
     
  5. BokuDev

    BokuDev

    Joined:
    Jan 2, 2014
    Posts:
    81
    Yeah I have my own damage script which is already on the sword, its just that I need the script to track the speed and force of the sword object, and then change the box collider to a trigger once the speed and force requirements are met.
     
  6. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    yes but since tracking the speed seems to be an impossibility, I'm recommending tracking the magnitude of the change in position.
     
  7. BokuDev

    BokuDev

    Joined:
    Jan 2, 2014
    Posts:
    81
    Ah I see. Good point. I will experiment!