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 Kerihobo · Nov 05, 2014 at 09:55 PM · charactercontrollerlerphitshake

Make a character controller shake.

Hi boys and girls, I have a fairly complex player_movement script that I wrote, myself. It utilises unity's character controller component.

I basically want to get characters hit by "special power beams" to stop responding to gravity and player input, and shake wildly on-the spot.

locking off gravity and player movement I can manage, but what's a good way to get character controller to shake? I know how to pass a vector3 into controller.move, like:

 controller.move(moveDirection);

but not sure how to use this to get a shaking effect. Any thoughts on an efficient way to do it? I am currently thinking I would create two lerp movements, one that interpolates between left and right movement and one for up and down movement, at varying speeds they could possibly get a good shaking effect?

a good or bad way to do it?

Comment
Add comment · Show 2
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 devluz · Nov 05, 2014 at 10:34 PM 0
Share

You can make use of the Random class to create random values you interpolate to by using lerp. But I would consider to shake only the camera. It usually (game depended) causes a cool shaking effect and it is less error prone as it doesn't cause any changes in the game logic and only changes the players view.

avatar image Kerihobo · Nov 05, 2014 at 10:48 PM 0
Share

ah using random is a cool idea. I'm making a 2D fighter with all players sharing the screen so if i do camera shake i may make it really subtle, but want characters to spaz when they get hit by power beams xD

2 Replies

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

Answer by podmaster · Nov 06, 2014 at 12:05 AM

Hey i leave you one script i made for a camera shake effect that is applied when a big spell explodes, maybe it gives you some ideas. It worked for me really nice you can twitch the timing and it has a linear ease down it starts at the maximum shake power and it decrease by the amount you want.

 private var ShakeAmount : float;
 private var ShakeDuration : float;
 private var TimeShaking : float;
 private var DefaultPositionX : float;
 private var DefaultPositionY : float;
 private var ShakeSlow : float;
 
 function Start () {
     DefaultPositionX = transform.localPosition.x;
     DefaultPositionY = transform.localPosition.y;
 }
 
 function Update () {
     if (TimeShaking <= ShakeDuration) {
     transform.localPosition.x = Random.Range(-ShakeAmount , ShakeAmount);
     transform.localPosition.y = Random.Range(-ShakeAmount /3 , ShakeAmount/3);
     TimeShaking += Time.deltaTime;
     ShakeAmount -= ShakeSlow;
     } else {
         transform.localPosition.x = DefaultPositionX;
         transform.localPosition.y = DefaultPositionY;
     }
 }
 
 function ShakeCamera(ExpPower : float, ExpDuration : float){
     ShakeAmount = ExpPower;
     ShakeDuration = ExpDuration;
     TimeShaking = 0.0;
     ShakeSlow = ShakeAmount / (ShakeDuration / Time.deltaTime);
 }



============== EDIT ============== Sorry i have to clarify i made this for a 2D game thats why i move the x and y position and not the rotation, but you can adjust that to your convenience. Hope it 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 Kerihobo · Nov 06, 2014 at 12:46 AM 1
Share

that's cool, the game I'm making is 2D as well. I think if i tweak this a little It will suit my needs, thanks man!

avatar image podmaster · Nov 06, 2014 at 12:55 AM 0
Share

Glad to help, remember to check the answer for the future if it worked ;) Cheers

avatar image
0

Answer by Haunter894 · Nov 05, 2014 at 11:39 PM

if you don't want the entire character to shake you can implement the script inside of the "Main Camera" that way instead of causing possible errors when your character is moving around you can just shake the camera thus giving the same illusion. Sorry if this really didn't help I'm fairly new to unity :s

Comment
Add comment · Show 1 · 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 Kerihobo · Nov 06, 2014 at 12:47 AM 0
Share

not too worried about errors in my character motion, I can sort that out just fine, just getting the shake to happen in the first place is where I'm gettin stuck.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

interpolate a move variable 0 Answers

Player Animation and control panel 2 Answers

Help: A collider attached to the character controller of a FPS does not collide 1 Answer

Character Controller Script 3 Answers

Controlled sphere/ Ball game 2 Answers


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