Search Unity

Shooting projectiles from two synchronised points

Discussion in 'Getting Started' started by tomatuxtemple, Sep 20, 2020.

  1. tomatuxtemple

    tomatuxtemple

    Joined:
    Oct 3, 2017
    Posts:
    1
    Hi! I'm starting with unity on a small project but i cant figure out a spawning script. Please help! Thank you :)

    I'm trying to shoot a projectile from left to right, and from top to bottom, each on a straight path from the spawn point through a bridge controlled by the user who can turn the platform to connect ends of the bridge to the ground letting the projectile pass. if the bridge will be in a wrong position the projectile will explode.

    the challenge i have is in making the spawner to spawn randomlly from left to right or from top to bottom because for that it has to move between two points

    can you help me figure out the script?

    thank you :)
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    If your two end points are called pointA and pointB, then a random point between them is:

    Code (csharp):
    1. Vector3 spawnPt = Vector3.Lerp(pointA, pointB, Random.Range(0f, 1f);