Search Unity

Question Add force and rotation to an object in One direction

Discussion in 'Scripting' started by Only4gamers, Jan 22, 2021.

  1. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Hello everyone,
    I am creating a Space RTS game. And I want to add similar movement like below video, before fighter ship will explode.

    Please start from 1 minute to see what I am talking about.
    As you can see in above video, when enemy ship killed, it go to same direction with rotation and then explode. I tried different approach but didn't able to get similar result.
    Please help.
    Thanks.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    From my viewing of the flight in the above video, it's just simple 3D flight, and there are a LOT of tutorials on that.

    Best way to succeed in this is to try some tutorials for game movement that is similar to what you are trying to achieve.

    Just beware that what you see in the above game is multiple layers of smoothly-integrated polished visual effects, post-processing effects, and camera treatments: there is camera wobble, field of view changes (perhaps driven by things that the game has deemed "interesting" such as enemies exploding?), regard-point changes, dollies, zooms, etc.

    Some of these effects might even be from the player himself while making the video, to dramatically glance in the direction where he knows will make the best video. There isn't any way to tell except to play it yourself.

    Each of those things contributes to the overall effect and you will not be able to make them all on your first try. You will iterate towards the feeling you want.

    ALSO: for spiffy camera stuff, always start with Cinemachine. It does a lot of stuff.
     
    Only4gamers likes this.
  3. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Thanks for reply. But I am not talking about special effects but pure scripts things only. In another video you can see better, what I am talking about:

    Start video from 1:10 and please watch at 0.25 speed for better look.
    So before enemy fighter explode:
    1. It rotating in z axis and going forward.
    2. Its rotation origin is not at center of the ship but little left or right of the ship.

    I succeed to move and rotate my ship in z axis. But its center of rotation is exactly at center of my ship which is not giving very good look. How to move center of rotation little left or right of the ship? That's all I wanted to know.
    This is my current line of script for rotation:
    Code (CSharp):
    1. transform.Rotate(0, 0, 10, Space.Self);
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Moving the center of rotation is as easy as putting an extra GameObject into your hierarchy and parenting a little deeper after offsetting one of them.
     
    Only4gamers likes this.