Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

2D How Do I add Randomly Generated Electricity in a Bridge?

Discussion in '2D' started by Dumitru, May 7, 2015.

  1. Dumitru

    Dumitru

    Joined:
    May 7, 2015
    Posts:
    80
    Hello, I am new to scripting and I need some help, I have a level that consists of a bridge that the player must pass, the bridge is long and it has an electrical current that appears randomly ( anywhere on the bridge ) and goes from Point A to Point B , The player starts at Point A and needs to pass Point B. The problem is, I have no idea on how I could attach the electricity to the bridge and make it spawn randomly between Point A to Point B and in between those 2 Points, after that the electricity is spawned, it must move towards either end of the bridge, Point A and B being the end of both sides of the bridge, and sometimes the electricity should spawn in a spot without moving for a few seconds before disappearing, the longer the player is on the bridge, the faster the electricity should spawn, the cherry on top is, the electricity should be somehow attached to the bridge in a way that it will "follow" the bridge. For example, when the player is on the bridge, the bridge detects the player's weight and 2d physics kick in and the bridge bends a little, the electricity should follow that bend. Sorry for my grammar because its my 4th language. Help will greatly be appreciated! Thank you for taking your time to read this message.
     
  2. DrowningFish

    DrowningFish

    Joined:
    May 6, 2015
    Posts:
    12
    Dumitru likes this.
  3. Dumitru

    Dumitru

    Joined:
    May 7, 2015
    Posts:
    80
    Thank you so much! I will try my best and follow, although i had a fast glance right now because I just got home from work, I will read all of it the next morning, I was just wondering is it possible with that guide to make it when the player is on the bridge, the bridge detects the player's weight and 2d physics kick in and the bridge bends a little, the electricity should follow that bend? Or is there another script that I will have to add, the other option being to attach the electricity to the bridge?
     
  4. DrowningFish

    DrowningFish

    Joined:
    May 6, 2015
    Posts:
    12
    Never tried that, but what I can think of is:

    since you want the laser to follow the bridge, the laser should be the child of the bridge.
    To have the bridge rotates or bends, the bridge (i think) should have a rigidbody2d, put as kinematic (so it won't drop due to gravity), then have a angular drag or linear drag,
    or play around with the other collider like joint collider / spring collider.

    I'm not really sure of these, but pretty sure no script is needed.
     
  5. Dumitru

    Dumitru

    Joined:
    May 7, 2015
    Posts:
    80
    Alright, thank you so much, I also have another problem with my Sprite quality, if you have the time, it would be really nice if you could help me with that. I spent my last 3 nights trying to play with the settings but the sprites aren't sharp and really good looking, I have posted on the forums, included some screen shots, again, thank you for your time and help!