Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by oliver-jones · Nov 15, 2010 at 03:43 PM · animationtransformvectorlocalrotationrecoil

Random Rotation To Animation HELP!

I have an animation on my rifle that is basically a recoil (kickback) that it triggered every time the 'Fire1' is pressed. But because it is playing the same recoil animation over and over again it looks a little bit 'fake'.

It is possible to add a slight random rotation animation to the recoil animation, so every time the recoil is played, the rotation differs slightly.

Now, currently I have got a script that changes the rotation randomly, but its not animation - so it looks like its 'snapping' (doesn't look smooth):

var SIG : Renderer;

function Update() {

if (Input.GetButton ("Fire1")) { animation.wrapMode = WrapMode.Clamp; animation.Play("SIG_fire", PlayMode.StopAll); SIG.transform.localRotation = Quaternion.AngleAxis(Random.value * 0.5, Vector3(1, 1, 0)); } }

SIG is the gun model.

Regards, Ollie

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by skovacs1 · Nov 15, 2010 at 04:11 PM

To get a smoother result, you could do something like adding one or more secondary animations designed to sync up with your current recoil animation and act on top of them with layers, using a synclayer if necessary and setting weight or using Blend to randomly set the effect of your offset on top of your recoil.

The correct approach would be to have your recoil be based on your gunshot direction and could be done in several different ways from separate animations for different gunshot positions or simplifying your recoil animation or using physics or driving that part of the animation in code.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Nov 15, 2010 at 05:35 PM 0
Share

What exactly are "synclayer and Blend"? I'm not familiar with them, if you could give an example, (or find a video example) that would be great. Your concept does sound like a good idea.

avatar image skovacs1 · Nov 15, 2010 at 07:20 PM 0
Share

Layers are for animations to happen simultaneously on top of each other and allow you to weight them. You can specify an animation's layer with something like animation["recoilAdjust"].layer = 1. SyncLayer would be used to sync up animations on a given layer which may not be necessary in your case. Blend is an automated interface to smooth in your animation weighting like Lerping your animation weight, but you could set the weight explicitly in the animationstate as equalsequals suggests with something like animation["recoilAdjust"].weight = Random.Range(0.0f,1.0f);

avatar image
0

Answer by equalsequals · Nov 15, 2010 at 04:15 PM

My suggestion is to look into using AnimationState layering. You could have a few AnimationClips applied and running simultaneously and weight the layers differently to achieve 'natural' results.

For example:

Have your standard recoil AnimationClip on layer 1, and then set another animation clip which controls only the rotation on layer 2. This rotation should be the maximum in which you want to rotate. From there, just before you tell these animations to play, you randomly choose a value between 0 and 1 and assign that to the weight of the rotation animation (layer 2). The blending that occurs will take into account the weight and should give you slightly randomized recoil which is unique every time.

Note: This is a very basic explanation and I am likely missing a couple details, but that should give you the general idea of where to look/start.

Hope that helps.

==

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Nov 15, 2010 at 05:34 PM 0
Share

I'm not familiar with AnimationState - infact, I'm kinda new to Unity anyway. What are Layers? and how do I apply animation to them?

Sorry if thats a really newby question.

Also what do you mean by weight.

Please, do go into detail lol I sure would appreciate it

avatar image equalsequals · Nov 15, 2010 at 08:44 PM 0
Share

It's an advanced topic for sure, if you're new to Unity or 3D in general it might be a little difficult to grasp. Let me try and revise my answer and see if I can't help.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Animation Continue 0 Answers

multiple Mixing Transforms 2 Answers

Animating transform problem (object returns to inicial position on animation end) 0 Answers

I am trying to make a gun recoil with an animation and in this script it only runs after the first mouse click. This is probably an easy fix I just can't seem to wrap my head around it. This is my script. 1 Answer

Are bone transforms in LateUpdate the transforms for the next or previous frame? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges