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
  4. Dismiss Notice

inheriting shooters momentum in projectiles

Discussion in 'Physics' started by NavarroFamily, Apr 12, 2021.

  1. NavarroFamily

    NavarroFamily

    Joined:
    Feb 15, 2016
    Posts:
    15
    Hello, I can’t for the life of me seem to get this to work, my projectiles use Rigidbodys

    Basically I just need a projectile physics script that works from a moving target.

    Imagine you’re riding a motorcycle north, and then fire a flare gun to the west .

    That flare should go west, but still maintain some of the northern momentum.

    I need that principle to work in my game.
    I’ve tried everything I could find Google.

    If anyone out there can show me a working example of a Rigidbody projectile that inherits it’s shooters momentum upon firing, It would be greatly appreciated.
    I need a hero lol, this last unity physics challenge is defeating me and my game, and I only have an hour or two a day to create between my work and kids.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,546
    Add the velocity of the "motorcycle" Rigidbody to the "projectile" Rigidbody.
     
  3. NavarroFamily

    NavarroFamily

    Joined:
    Feb 15, 2016
    Posts:
    15
    For some reason that isn’t working for me correctly.
    How are you adding the the velocity exactly
    Via add force, or just a simple +?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,546
    You only said "that isn't working" which could mean anything. Maybe provide some more info and scripts on how it's not working and what you're doing.

    If you don't follow what I just suggested then honestly I'm not sure how else to tell you as it's pretty basic. Certainly AddForce has nothing to do with getting the velocity of the motorcycle using the velocity property and adding it to the projectile velocity you choose.

    projectile.velocity = baseProjectileVelocity + motorcycle.velocity
     
  5. NavarroFamily

    NavarroFamily

    Joined:
    Feb 15, 2016
    Posts:
    15
    That’s exactly what I’ve done, it just doesn’t behave like any kind of real physics I’ve ever seen. The bullet looks like it’s coming from way off to the side. I can see a noticeable difference in the way the bullet behaves from before, it’s definitely inheriting the players velocity, but it’s still unusable.

    To be fair, I followed exactly what you mentioned, but I didn’t know how to explain the funky physics I’m experiencing. I can’t post a script at the moment because a tornado knocked out my neighborhoods internet, so I’m phone bound as far as forums go, I guess my question will have to wait till I can post a script again. I was just hoping for an example I could read line by line and figure it out from there.
     
    Last edited: Apr 13, 2021
  6. NavarroFamily

    NavarroFamily

    Joined:
    Feb 15, 2016
    Posts:
    15
    I just figured out what I’m going to do, it completely out there but it looks the way I want it. I’ll post my script once the internet guys hook my box back up. But if anyone is looking for more of an action movie style physics for shooters, it might help.

    thanks for your help
     
    MelvMay likes this.
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,546
    Good luck, hope you get connected again soon!