Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

object shaking unity

public class ObjectShake : MonoBehaviour {

	private Vector3 originPosition;
	private Quaternion originRotation;
	public float shake_decay = 0.002f;
	public float shake_intensity = .3f;

	private float temp_shake_intensity = 0;
	
	void OnGUI (){
		if (GUI.Button (new Rect (20,40,80,20), "Shake")){
			Shake ();
		}
	}
	
	void Update (){
		if (temp_shake_intensity > 0){
			transform.position = originPosition + Random.insideUnitSphere * temp_shake_intensity;
			transform.rotation = new Quaternion(
				originRotation.x + Random.Range (-temp_shake_intensity,temp_shake_intensity) * .2f,
				originRotation.y + Random.Range (-temp_shake_intensity,temp_shake_intensity) * .2f,
				originRotation.z + Random.Range (-temp_shake_intensity,temp_shake_intensity) * .2f,
				originRotation.w + Random.Range (-temp_shake_intensity,temp_shake_intensity) * .2f);
			temp_shake_intensity -= shake_decay;
		}
	}
	
	void Shake(){
		originPosition = transform.position;
		originRotation = transform.rotation;
		temp_shake_intensity = shake_intensity;

	}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: source a listbox by property of object c# 
Csharp :: string join inside foreach loop c# 
Csharp :: html tag inside razor tag 
Csharp :: get access to all controls with a specific tag in C# 
Csharp :: unity use of possibly unassigned field struct 
Csharp :: windows forms link listbox to array 
Csharp :: how to create more accurate searching c# 
Csharp :: isdaylightsavingtime in c# 
Csharp :: Set orientation of moving object towards it movement direction 
Csharp :: .net ssh, wait command execute 
Csharp :: An error occurred while deserializing the property of class Truncation resulted in data loss. 
Csharp :: unity having virtual start 
Csharp :: C# Printing Variables and Literals using WriteLine() and Write() 
Csharp :: C# string go to line 
Csharp :: Query Parent-GrandChild single 
Csharp :: postgres .net 6 datetime issue 
Csharp :: getString 
Csharp :: nunjuck if exist 
Csharp :: c# return default "" if null 
Csharp :: unity inspector sliders 
Csharp :: list<string,string c# 
Csharp :: copy file 
Csharp :: unity trigger not detecting collision 
Csharp :: how to change the width of a panel unity 
Csharp :: c# jump space 
Csharp :: c# an object on upper level cannot be added to an object 
Html :: html empty character 
Html :: align eliment in center of row bootstrap 
Html :: how to remove suggestions from input field 
Html :: verbalna komunikacija 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =