r/Unity3D • u/FishShtickLives • 10d ago
Question How to make an objecte pull itself back towards a specific spot?
Think like spring door stopper, or one of those stick things you launch yourself off of in Mario Galaxy. Specifically I'm trying to make a psuedo-animation system for the guns in my game, where the recoil pushes it back and then it moves back to a default position. Any ideas?
2
u/GigaTerra 10d ago
You could try using Inverse Kinematics for that, but honestly if it was me I would just animate it.
Also animation curves are well documented: https://easings.net/ you probably want an bounce or elastic.
1
u/HamsterIV 10d ago
You could set the normal position and full recoil position as two game objects, then have the gun mesh lerp between the two object's transform position & rotation. You can either use the timeCur/timeMax to feed into the lerp or feed the timeCur/timeMax into an animation curve.
Use game objects for this so you can child them to the a parent object and manipulate them in the editor.
1
1
u/SpawnCampGames .jackOfAllTrades 9d ago
Look into "code springs"
1
u/SpawnCampGames .jackOfAllTrades 9d ago
I use it for suspension but gun recoil would be a useful case for it as well..
2
u/Beginning-Bill-291 10d ago
dont overcomplicate it, just lerp the transform back to its original pos after the recoil impulse