Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

Search the Community

Showing results for tags 'light behaviour'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • GENERAL
    • Introduce yourself
    • Discussions
    • Showcase
    • Need help?
    • Seeking team members?
    • Offtopic
  • RESOURCES
    • unity3D | Example Projects
    • unity3D | Scripts
    • unity3D | Shaders
    • unity3D | Tutorials
    • 3D models
    • Animated 3D Models
    • Graphic design
    • Textures
    • Sounds
    • Other
  • FREE FPS PROJECT
    • FPSKit Download
    • FPSKit Modifications/Tutorials
    • FPSKit WIP/Showcase
    • Discussions / Bug reports
  • SELL | REQUEST
    • Sell
    • Request
  • Mars' Modular Multiplayer Photon FPS Kit's Topics
  • Mars' Modular Multiplayer Photon FPS Kit's Reviews
  • Mars' Modular Multiplayer Photon FPS Kit's Updates
  • Mars' Modular Multiplayer Photon FPS Kit's Tutorials
  • Busy People's Introductions
  • Photon's Tutorials
  • Photon's Photon General
  • Photon's Showcase

Categories

  • Free Projects
  • Free Assets
  • Game Demos
  • Photon's Files

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


YouTube URL


Facebook URL


Twitter URL


IndieGoGo URL


Kickstarter URL


IndieDB URL


GreenLight URL


Location:


Interests

Found 1 result

  1. Hi there, this is a fire light behaviour script I just made and I just wanted to share it It is not advanced, it is just lerping the position and the light's intensity to somewhat simulate a fire's light. Anyways, just attach the script to the fire's light, tweak the values and you're good to go Copy the below, then create a new C# script, and then paste the code in it(or write it all if ya want ). /* * Author: DeepWolf * Description: Simulates a light's behaviour of a fire. * * Usage: * Attach this script to the light source of the fire and tweak the values. */ namespace DeepWolf.Utilities { using UnityEngine; /// <summary> /// Represents a <see cref="FireLight"/>. /// Handles the breathing and the movement of the fire. /// </summary> [RequireComponent(typeof(Light))] public class FireLight : MonoBehaviour { /// <summary> /// How frequently the <see cref="FireLight"/> will find a new position. /// </summary> [Header("[Movement]")] [SerializeField, Tooltip("How frequenly the light will find a new position.")] private float moveFrequency = 0.15f; /// <summary> /// The lerp speed of the fire movement. The lower the speed, the smoother the movement will be. /// </summary> [SerializeField, Tooltip("The lerp speed of the fire movement. The lower the speed, the smoother the movement will be.")] private float moveLerpSpeed = 1.0f; /// <summary> /// The min and max value of how much the <see cref="FireLight"/>'s <see cref="Transform"/> is able to move in the x axis. /// </summary> [SerializeField, Tooltip("The min and max value of how much the light is able to move in the x axis.")] private Vector2 xMoveLimit = new Vector2(-0.2f, 0.2f); /// <summary> /// The min and max value of how much the <see cref="FireLight"/>'s <see cref="Transform"/> is able to move in the y axis. /// </summary> [SerializeField, Tooltip("The min and max value of how much the light is able to move in the y axis.")] private Vector2 yMoveLimit = new Vector2(-0.0f, 0.15f); /// <summary> /// The min and max value of how much the <see cref="Light"/>'s <see cref="Transform"/> is able to move in the z axis. /// </summary> [SerializeField, Tooltip("The min and max value of how much the light is able to move in the z axis.")] private Vector2 zMoveLimit = new Vector2(-0.2f, 0.2f); /// <summary> /// The breathing frequency of the <see cref="Light.intensity"/>. /// </summary> [Header("[Intensity Breathing]")] [SerializeField, Tooltip("The breathing frequency of the light's intensity.")] private float IntensityBreathFrequency = 0.5f; /// <summary> /// The speed of the intensity transition. /// </summary> [SerializeField, Tooltip("The speed of the intensity transition.")] private float intensityLerpSpeed = 2.0f; /// <summary> /// The minimum the <see cref="Light.intensity"/> value can be. /// </summary> [SerializeField, Tooltip("The minimum the light's intensity value can be.")] private float minIntensity = 0.5f; /// <summary> /// The maximum the <see cref="Light.intensity"/> value can be. /// </summary> [SerializeField, Tooltip("The maximum the light's intensity value can be.")] private float maxIntensity = 1.0f; /// <summary> /// The <see cref="Time.time"/> till the next move transition. /// </summary> private float nextMove; /// <summary> /// The <see cref="Time.time"/> till the next intensity transition. /// </summary> private float nextIntensity; /// <summary> /// The <see cref="Light.intensity"/> value to transition to. /// </summary> private float targetIntensity; /// <summary> /// The <see cref="Light.intensity"/> value to transition to. /// </summary> private Vector3 targetPosition; /// <summary> /// The original <see cref="FireLight"/> position. Used to offset the move limits from the orignal position when looking for a new position to transition to. /// </summary> private Vector3 originalPosition; /// <summary> /// The <see cref="Light"/> component on the <see cref="FireLight"/>. /// </summary> private new Light light; /// <summary> /// The <see cref="Transform"/> component on the <see cref="FireLight"/>. /// </summary> private new Transform transform; private void Awake() { light = GetComponent<Light>(); transform = GetComponent<Transform>(); originalPosition = transform.position; } private void Update() { HandleMovement(); HandleIntensityBreathing(); } /// <summary> /// Handles the movement transition to the <see cref="targetPosition"/>. /// </summary> private void HandleMovement() { // Move to target position transform.position = Vector3.Lerp(transform.position, targetPosition, moveLerpSpeed * Time.deltaTime); if (nextMove <= Time.time) { FindNewPosition(); nextMove = Time.time + moveFrequency; } } /// <summary> /// Finds a new <see cref="targetPosition"/> to transition to. /// </summary> private void FindNewPosition() { float newX = originalPosition.x + Random.Range(xMoveLimit.x, xMoveLimit.y); float newY = originalPosition.y + Random.Range(yMoveLimit.x, yMoveLimit.y); float newZ = originalPosition.z + Random.Range(zMoveLimit.x, zMoveLimit.y); // Find new position targetPosition.Set(newX, newY, newZ); } /// <summary> /// Handles the breathing of the <see cref="FireLight"/> by changing the <see cref="Light.intensity"/> smoothly to the <see cref="targetIntensity"/>. /// </summary> private void HandleIntensityBreathing() { light.intensity = Mathf.Lerp(light.intensity, targetIntensity, intensityLerpSpeed * Time.deltaTime); if (nextIntensity <= Time.time) { FindNewIntensity(); nextIntensity = Time.time + IntensityBreathFrequency; } } /// <summary> /// Finds a new <see cref="targetIntensity"/> to transition to. /// </summary> private void FindNewIntensity() { targetIntensity = Random.Range(minIntensity, maxIntensity); } } }
×
×
  • Create New...