Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help with weapon movement.

Discussion in 'Scripting' started by slavingia, May 7, 2007.

  1. slavingia

    slavingia

    Joined:
    May 7, 2007
    Posts:
    9
    OK, so I was going through the FPS tutorial to get a grip on Unity, and now I'm stuck. My RocketLauncher refuses to follow my FPS controller, even though mouse-pointing works.

    Any help?

    - Sahil
     
  2. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    Put the rocket launcher as a child of the Character Controller

    Omar Rojo
     
  3. slavingia

    slavingia

    Joined:
    May 7, 2007
    Posts:
    9
    I did that, but it still refuses to follow it. Whenever I start the game, the rocket drops about 2 pixels, maybe that has something to do with it?

    - Sahil
     
  4. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    does the rocket launcher have a rigidbody?
     
  5. slavingia

    slavingia

    Joined:
    May 7, 2007
    Posts:
    9
    Yes it does. :/ It seems like it should work, but it doesn't. I did it right with the grenade spheres, but it doesn't seem to work with this.
     
  6. slavingia

    slavingia

    Joined:
    May 7, 2007
    Posts:
    9
    UPDATE: I skipped that part and did the machine gun, and that gun works fine, it's just the launcher that doesn't... now it seems that the launcher is going front when I hit back >.<.

    PLEASE HELP. :D

    - Sahil.
     
  7. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    Try to find the difference between the machine gun and the rocket launcher.. if one works.. i don't have much experience with rigidbodies..

    Omar Rojo
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You don't want the rocket launcher to have a rigidbody. If it has a rigidbody, it will interfere with the movement of the character controller.

    --Eric
     
  9. slavingia

    slavingia

    Joined:
    May 7, 2007
    Posts:
    9
    OK I got that part to work. However, projectiles now refuse to exit their respective weapons. In the H. View it shows rockets and particle systems beind created and then destroyed, but they can't be seen in Scene View.
     
  10. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    find the rocket you are instantiating in the project view. Drag into scene view, make sure you can see it. If you can, fine. If not look in the layers tab on the inspector-depending on how your doing this, there may be no camera spcifically rendering your rocket model. Move it in front of fps camera to be sure- you should be able to see it in game view. CMD-delete it from hieracy if all looks ok..
    If you cant see it, Change its layer till you can. If its still not working, select rocket in scene, go through the categories in the inspector-make sure a renderer and a mesh to render is assigned.

    Go well and be patient, this all takes time to understand..
    AC
     
  11. slavingia

    slavingia

    Joined:
    May 7, 2007
    Posts:
    9
    Everything renders fine. The first few shots taken seem to be all right ( a bit too much below aim though) but then they just stop appearing. I paused and checked the rocket's location and it's way below the level mech... anyone know why? Same with the machine gun, the bullets seem find except being below the aim and then just stop working.
     
  12. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    If you have rigidbodies on your guns they will fall down due to gravity and act like physical objects should. They will not necessarily follow their parent.
     
  13. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    The Rocket/gun models are children of the gameobjects with the relevant scripts, right? does the gameobject with the script match the position of the gun barrel tip?

    The Rockets do "run out", which is set in the inspector...

    You dont have a timed object destructor on the machinegun/rocketlauncher GO's with scripts attatched do you? If so remove...

    I had a similar problem the first time I did this ages ago. I gave up, returnrd to it some weeks later and everything went fine...

    Dont sweat it man. Everything gets easier with time...
    The thing is, this Tech is so good, it makes us passionate, and stay up waaay too late, and the obstacles are infuriating.
    But everything is possible. Developing 3d games takes a lot of skill, patience, and other stuff.
    AC

    ps if things are a mess, and your doing the FPS tut, just start over. Once you get it, you can apply these scripts fairly easily to most game types. HTH
     
  14. slavingia

    slavingia

    Joined:
    May 7, 2007
    Posts:
    9
    Thanks for all the help guys! I think I've got everything settled (hopefully). WIll def. be getting the Pro version sometime.

    - Sahil.
     
  15. slavingia

    slavingia

    Joined:
    May 7, 2007
    Posts:
    9
    For some reason the bullets and rockets don't go forward... they end up hitting a random spot or flying way under the map...
     
  16. slavingia

    slavingia

    Joined:
    May 7, 2007
    Posts:
    9
  17. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Ignore the fact that my guns have different names. Does your hieracy look like this?

    See where the gizmo is?right in the middle. Yours must be somewhere else. Dissconnect all your objects and position them where you see the axis gizmo in this pic, then reconnect. Your picture indicates that some object in your hieraqcy is away from the player creating an axis where you dont want it.

    Unparent, reposition, reparent
    AC
     

    Attached Files:

  18. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    make sure the projectiles (rockets) have rigidbodies, just not the launcher-- I think the bullets are raycasts...