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 shahinexir · Aug 13, 2012 at 04:45 PM · instantiatejumpshootingdisablefire

how to disable instantiating projectile for the moment when the player jumps and hits the space bar to fire?

hii . i have a 2d game . and have a player who can jump whith up arrow and fire with space bar . now i want to disable the space bar when i jump , so that if i hit the space when i jump it wouldnt work and dont shoot any projectile for a while . the reason that i want to do this is that now if i hit the up arrow and jump and while jumping hit the space bar to fire it fires projectile but jumps again while its in the air and goes a lil upper!!! tnx

Comment
Add comment · Show 1
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 ScroodgeM · Aug 13, 2012 at 05:38 PM 0
Share

the reason that i want to do this is that now if i hit the up arrow and jump and while jumping hit the space bar to fire it fires projectile but jumps again while its in the air and goes a lil upper

i think it can be fixed and it will be more correct solution then just disabling firing.

anyway, without scripts sources we can't help you. post a script where you handle jumping and firing.

2 Replies

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

Answer by shahinexir · Aug 13, 2012 at 06:22 PM

here is my player script . really apreciate if u can help me :

var playerSpeed : int;

var jumpHeight : int;

var fireBallPrefab : Rigidbody;

function Update () {

//1- player movement

 amtToMove = playerSpeed * Input.GetAxisRaw("Horizontal") * Time.deltaTime;     // amount to move the player 
   

    
 transform.Translate(Vector3.right * amtToMove);                                
         

//------------------------------------------------------------------------

//2- player rotation...!

  if (Input.GetKey("left") || Input.GetKey("a"))
  {
    
    transform.rotation = Quaternion.Euler(0,180,0);                        

  }      
  if (Input.GetKey("right") || Input.GetKey("d"))
  {
  
    transform.rotation = Quaternion.Euler(0,0,0);    
        
  }



//--------------------------------------------------------------------------

//3- player jump

 // player can countinusly jump when you hold the up button. if its transform position in y axis is equal to 0.73(on the ground) 
 

if ( (Input.GetKey("up") || Input.GetKey("w") ) && transform.position.y == 0.73)

   {
   
     amtToJump = jumpHeight + Time.smoothDeltaTime ;
     
     transform.Translate(Vector3.up * amtToJump );
     

   }
   
 
 
 //4- instantiate fireBall
 
    
 if (Input.GetKeyDown("space"))
 {
    var tempfireBall : Rigidbody;
    tempfireBall = Instantiate(fireBallPrefab,Vector3(transform.position.x , transform.position.y, transform.position.z),transform.rotation);
 }
    

}

Comment
Add comment · Show 8 · 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 ScroodgeM · Aug 13, 2012 at 06:37 PM 0
Share

very strange script 8)

in this script you can jump only if your position is in height 0.73. so. if you are jumping already, you are not able to jump again. also, in "space" button nothing can let player jump again. something here is not explained still.

avatar image shahinexir · Aug 13, 2012 at 06:45 PM 0
Share

thats right.i want to make a gameplay like super mario . can u understand what i mean? i want that kindda jump. have u any idea about jumping? what should i do? :( also about rotation there is a problem that if i want to move to left the player rotates to the left but walks to right direction!!! donno why!!! really need some edit

avatar image ScroodgeM · Aug 13, 2012 at 06:51 PM 0
Share

in supermario player can jump not only from ground, but from other object that has other height. so your script is incorrect a little. also, how in your case player is falling down? is it rigidbody with gravity ot smthing else?

by default transform.Translate moves object in local space, but you use it like in world space. so:

  • or move object always in one direction in local space and rotate separately

  • or move object in world space

transform.Translate(Vector3.right * amtTo$$anonymous$$ove, Space.World);
avatar image shahinexir · Aug 14, 2012 at 04:15 PM 0
Share

yes , i have rigid body with gravity on my player . and also tnx alot for your help.its now rotating and moving well ;) about jump height , i know what youre saying and your right but there is a problem . if i remove the limit 0.73 then if i jump there wont be any limit on jump height ony axis , and the player will fly to the sky and come back again after a few seconds by gravity force!! . so what do u think? do u have any idea how to fix it ? tnx . and yes its a lil wierd script :D but im new . so really apreciate if u tell me wich parts are wrong or look strange . tnx

avatar image ScroodgeM · Aug 14, 2012 at 08:20 PM 0
Share

once you use a rigidbody with gravity, to jump able you can just check if rigidbody velocity in Y axis is close to zero:

if ( (Input.Get$$anonymous$$ey("up") || Input.Get$$anonymous$$ey("w") ) && $$anonymous$$athf.Abs(rigidbody.velocity.y) < 0.01)

and, to jump simply add vertical speed:

rigidbody.velocity.y = 5.0;
Show more comments
avatar image
0

Answer by subcod · Aug 13, 2012 at 06:22 PM

1.make a raycast under the player

var ableToJump:boolean; If(!(Physics.Raycast(transform.position,Vector3.down,distance))) {

//Everything in here executed when the character has jumped so high the raycast doesn't //touch the ground

ableToJump=False; } if(ableToJump&&Input.getButton("Jump"))

{ transform.position.z+=5; }

Comment
Add comment · Show 2 · 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 shahinexir · Aug 14, 2012 at 04:20 PM 0
Share

would u pls explain me about the first if ( condition ) part? what is actually happening there ? and what is that ({ transform.position.z+=5; } ) doing? and why z axis?! im making a 2d game tnx .

avatar image subcod · Aug 21, 2012 at 09:59 PM 0
Share

sorry im late, The first if condition is to check if the player is on the terrain or object.

transform.position.z+=5 is the same as transform.position.z=transform.position.z+5

z is the direction of the transform

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

9 People are following this question.

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

Related Questions

Third Person Shooting Script Stopped Working 1 Answer

Destorying prefab and instanstiating again? 0 Answers

Checking if object intersects? 1 Answer

Enemy Damage problem 1 Answer

how do i stop automatic firing? 3 Answers


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