Let's talk about Lissajous curves. There are plenty of websites that go into great detail about all the history, equations, and cool stuff you can do with Lissajous curves. I'll explain it simply and in terms of weapon sway. Think in your mind of your favorite FPS. As you walk the weapon typically sways horizontally and vertically in nice harmonic pattern. This complex motion in the x and y dimension is a Lissajous pattern.
Now, to program sway via Lissajous curves you can simply combine sin and/or cosine waves. There are different forms of the equations that use sin and/or cosine waves but for our example we will use 2 sin waves. Basically the goal is to oscillate vertically and horizontally harmoniously. From there you can customize your waves to get the effect you want.
This code will get you that traditional figure eight sway (this is a Unity C# snippet). Enjoy!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleWeaponSway : MonoBehaviour
{
[SerializeField]
Transform weapon;
[Range(0, 1f)]
[SerializeField]
float verticalSwayAmount = 0.5f;
[Range(0, 1f)]
[SerializeField]
float horiztonalSwayAmount = 1f;
[Range(0, 15f)]
[SerializeField]
float swaySpeed = 4f;
// Update is called once per frame
void Update ()
{
float x = 0, y = 0;
y += verticalSwayAmount * Mathf.Sin((swaySpeed * 2) * Time.time);
x += horiztonalSwayAmount * Mathf.Sin(swaySpeed * Time.time);
weapon.position = new Vector3(x, y, weapon.position.z);
}
}
Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. softair san marino
ReplyDeleteThanks For sharing this Superb article.I use this Article to show my assignment in college.it is useful For me Great Work. softair san marino
ReplyDeleteAt the point when strike is submitted with a destructive weapon without goal to slaughter, it is named irritated ambush. This is a third-degree lawful offense.m4 elettrico
ReplyDeleteWhen I put this on my weapon it disappears? What's going on?
ReplyDeleteAs the latest standard for Cascading Style Sheets (CSS), CSS3 makes it easier for programmers to create web applications that look good on both computers and mobile devices. Also, the developers can combine HTML5, CSS3, and JavaScript to build a variety of mobile web apps. Despite being backward-compatible with earlier versions of CSS, CSS3 includes several new modules.
ReplyDelete