Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by skEncrypt · Oct 05, 2012 at 09:19 PM · axiscubeshootalong

Trouble shooting cube along in a straight line

Hey guys! I've been a pretty long time C# programmer and a moderate amount of time spent with js, but am pretty new to Unity so am hoping for some help, I'm currently attempting to create a sort of multiplayer online arena type of game where players will face off against each other in a FFA format so I've got my Plane, PlayerCube and EnemyCubes, HP bars and all that jazz but I'm running into a bit of a problem when it comes to projectiles, here's the code I tried after my first attempt failed:

 function Update () {
     // Put this in your update function
     if (Input.GetKeyDown(KeyCode.Space)) {
 
     // Instantiate the projectile at the position and rotation of this transform
     var clone : Transform;
     clone = Instantiate(projectile, transform.position, transform.rotation);
     // Add force to the cloned object in the object's forward direction
     clone.rigidbody.AddForce(clone.transform.forward * shootForce);
     }
 }

so when I run this piece of code my PlayerCube is able to shoot cubes but they actually fall through the floor after about half a second and I need them to be able to travel in a straight line (without falling through the ground or accelerating upwards).

I usually like to work through these things on my own but this has had me stumped for about an hour now, I tried doing "clone.rigidbody.velocity" to make the cube come out a tad bit more upwards but then the cube eventually goes flying into the air later in the screen, I want people to be able to hit other players who are on the plane on the other side of the screen so it needs to really travel along the same axis without falling or going higher.

Would really appreciate any help with this! Also I've been trying to destroy the projectile cubes when they hit an enemy cube with:

 function OnCollisionEnter(theCollision : Collision)
 {
     if(theCollision.gameObject.tag=="Bullet") 
     {
         Destroy(gameObject);
     }
 }

but it doesn't seem to work for me, I have the trigger ticked on the enemy cube but as usual the projectile cubes just pass straight through it and keep travelling.

Thanks in advance for the help!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KiraSensei · Oct 05, 2012 at 10:10 PM 0
Share

Simple question, did you uncheck the gravity parameter of your prefab rigidbody ?

avatar image skEncrypt · Oct 05, 2012 at 10:21 PM 0
Share

oh wow, never actually expected something this simple haha, over complicating seems to be the source of my problem yet again!

Thanks very much for the tip, seems I have a lot more to learn about unity, now I just have to figure out why my projectile cubes aren't colliding correctly with the enemy cubes.

Also I have no idea how to mark your comment as a correct answer or if I'm even supposed to?

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by KiraSensei · Oct 05, 2012 at 10:24 PM

This should help you with your remaining problem (I asked this kind of question before and had a lot of trouble correcting the problem ...) :

here

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image skEncrypt · Oct 05, 2012 at 10:44 PM 0
Share

that helped a lot! thanks very much, I have everything fixed now :)

avatar image
0

Answer by nikescar · Oct 05, 2012 at 10:25 PM

Set the Rigidbody constraints of your bullet prefab from the inspector. You can freeze the position and rotation of any axis.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make new Axis? 2 Answers

Rotate cube in two direction not working 1 Answer

Why won't my crate fire? 3 Answers

How i can create a cube with specific coordenates? 3 Answers

Flipped objects Rotation issues 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges