How do i make objects use the spring system, like the documentatiom says?

Howdy, i want to do what the documentation says, create an arrow wobble when it hits a wall. however for the life of me i can't figure out how to DO that, there doesn't seem to be anything in the demo about and the Spring script in motion doesn't pull from monobehavior or anything and i don't know if that's what i'm supposed to use. do i NEEED to make my own script to utilize those ideas (i can, but it seems weird that i'd have to?)

how do i actually use the spring system on jello, or an arrowhead, or such things. the only uses of it SEE are for the camera and weapon stuff for character

EDIT: Doc page for reference https://opsive.com/support/documentation/ultimate-character-controller/animation/springs/
 
First you'll need an instance of the Spring class on your object (e.g. on the arrow prefab). Then you'll need to use Spring.Initialize (and Spring.Destroy in OnDestroy). I'd recommend taking a look at FirstPersonPerspectiveItem.cs for examples of how the Spring class is actually used during runtime.
 
So i need to make my own script? As my arrow prefab doesn't have any springs on it and i cna't just assign the spring script to anything as it lacks monobehavior backing. None of the demo stuff as far as i can tell, outside of characters, use any spring stuff.
 
Yes, that is correct. The spring system is a generic class so it can be used in a wide variety of situations, but it is only used by the character controller in a limited number of instances.
 
Yeah you'd need to set all this up in a custom component, unfortunately the demo scene doesn't have any examples of this specific case as far as I'm aware.
 
Okay cool that's what i needed to know. It'd be fantastic if you could toss an example of that being used somewhere in a later demo version, as it's an advertised cool feature that just isn't really communicated well. ya'll worked hard on it, might as well show what it does. i'll take a look into making those scripts, much appreciated.
 
Howdy, i know i closed this already but is there any chance i could get like a quick banged-together test script to just show off "thing shakes with spring when it hits wall" or something? Maybe some test-script laying around for internal tests? it doens't need to be fancy. I've figured out what ya'll meant and i'm trying to work it into my own custom scripts based off the examples that are in fpsperspectiveitem and ect, but just seeing something simple made with it would be a huge boon. this SOUNDS really cool but honestly without being able to see what it does to non arm stuff makes it hard to visualize.
 
Something like this

C#:
using UnityEngine;
using Opsive.UltimateCharacterController.Motion;

public class TestObjectSpring : MonoBehaviour
{
    public Spring spring;
    
    void Start() {
        spring.Initialize(false, false);
    }
    
    void LateUpdate() {
        transform.localPosition = spring.Value;
    }
}

This is with a basic gameobject with an empty parent. You'll need to set the position of the object to the spring's value whenever the spring updates, which I've put in LateUpdate since this spring is using Update as its tick location. You can then move the object away from its RestValue however you want, e.g. with spring.AddForce.
 
Radical, i got that going (threw in an OnImpact callback to make it flinch on damage) and it lurches away, then drifts back. It's actually alot like some dotween hitshakes i've done before. Imma put it on the arrow, then a thrown spear, adn in general see what i can get away with. if it's as useful a bit of procgen anim as it seems, then that could shortcut alot of "make thing wiggle when hit" without needing ot make custom anims or scripts.

Much appreciated! Like i mentioned when UCC is updated next i really recommend you just throw something like this in there. in the demo fuck, put it ON the arrow and just have a bool toggle for if it should activate or not. put a floating target out in the free roam area that shakes when shot or somehting, ect. the springs ya'll made are a huge selling point and it very much seems like that area is being wildly under advertised.

Hell, just put exactly this script in the spring documention. it's simple but it gets some of the idea across.

using UnityEngine; using Opsive.UltimateCharacterController.Motion; using Opsive.Shared.Events; public class TestObjectSpring : MonoBehaviour { public void Awake() { EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact", OnImpact); } public Spring spring; void Start() { spring.Initialize(false, false); } void LateUpdate() { transform.localPosition = spring.Value; } private void OnImpact(float amount, Vector3 position, Vector3 forceDirection, GameObject attacker, object attackerObject, Collider hitCollider) { Debug.Log(name + " impacted by " + attacker + " on collider " + hitCollider + "."); spring.AddForce(forceDirection); } public void OnDestroy() { Debug.Log("aaa"); EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact", OnImpact); } }

The fpsitemperspective and ect scripts DO show it in a complex use, but there's so much going on in that script that actualy parsing out what individually is happening is tough. this is simple but i get it and have ideas about how to expand it.

anyway, much appreciated!
 
Top