Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Shealei · Jul 17, 2011 at 03:48 PM · camerajavascriptguihitmark

I want a HitMark(GUI) system like in Crysis-CoD that indicates where i am hit from and also a Camera/Screen shake effect

Hi guys, i am at the final stage of my FPS game but i need to make a hit indicator like Crysis/CoD and add a camera shake effect. I am a java user. I've found some C reference to the hitmark but didnt understand anything.

As for the hitmark: I found a code like this;


 public hitmarkerTime = 0.2; 
 // Again I am no C# guy so I have almost no idea how to declare variables in C#
 
 if (hit.collider.gameObject.tag == "Enemy")  {
 
       displayHits = true;
 
 }
     
 else {
     displayHits = false;
 }
     
     
  public void OnGUI()
 {
     if (displayHits) 
     {
         timer();
         GUI.DrawTexture(new Rect(Screen.width / 2 - hitMark.width / 2,  Screen.height/2- hitMark.height/2,hitMark.width, hitMark.height), hitMark);
     }
 }
 
 
 void Timer() {
 
     yield WaitForSeconds(hitmarkerTime);
     displayHits = false;
 }


The scipt in the box is the key i think but i cant really work it out. I havent slept in like 24 hours now. I dont understand how that works and how can i implement that. I have absolutely "0" idea about this, i am moderate level in coding so far so i will accept any answer here.

As for the Camera Shake: Well i tried using an animaton to shake my camera and it seemed quite fine, but here is the problem. If i use the animation to shake my camera when i am hit by raycast or my HP goes down, if i am looking up or down(Anywhere that isnt the exact default position of my camera when i start the game), the animation(which is really short timed) turns the camera fine but it also resets the position to my default for the turning.

What i mean by this is, consider that my camera is at transform.position,transform.translate of variables (0,0,0),(0,0,0) when i turn the camera in 0.1 seconds and back for 15 degrees to the left along Z axis for expample, my translate becomes (0,0,15), but what if i was looking up at the moment my animation played, my camera would be at a translate like (47,55,120) and if i play the animation now, it will instantly go to the translate value (0,0,15) thus centering the camera once its played. This isnt what i want at all. I can move the camera with script using (x,y,z+15) but that will be too fast i think. And i dont know an effective way of applying some speed to that. Any help is appriciated.

  1. I want a HitMark like Crysis and CoD indicating where i am hit from on the screen, fashing red rectangles.

  2. I want a good cam shake or screen shake effect when i am hit.

Just give me some ideas and bits of scripts or just a referance i'll get the results myself.

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 SilverTabby · Jul 17, 2011 at 04:44 PM 2
Share

I can see that you have tried a large number of things before you came here to ask the question, which puts you well ahead of the average person who comes here with a question.

That said, because of the way this question is asked, formatted, and titled, I do not think you will get any one answer that helps you.

I would try the following steps to get a more reliable response:

1) Break your HUGE question down into several smaller ones. For example, ask a question on how to get the markers to show up on your screen. Then ask a second question about how to get the camera to shake on command, and post the relevant code. This way you are more likely to get a response because people like me see giant wall of text and leave.

2) Do not use the terms "need help" "I want" "like in [game name]" or anything along those lines in your question title. $$anonymous$$any people who can actually help you will see the title of the question, laugh and ignore you (I almost did). Also, exclamation points decrease the chance of an answer by about 20% each.

3) Spell check. Use it. (referance != reference)

4) Don't be scared by C#. It looks complex but it is almost identical to Java and javascript. Look it over and ask what does This line do? What does that line do? How are they declaring a variable? What syntax is different than what I know? What syntax is the same as what I know?

5) Get some sleep. Go to a movie. Take some friends out to dinner. Take your $$anonymous$$d off of it. I've solved more program$$anonymous$$g problems in this way than I have pouring over scripting references. It works.

avatar image Shealei · Jul 17, 2011 at 06:32 PM 0
Share

Thanks to you too mate :). I'll consider your advices on using the community. Got your reference != referance joke tho, thats a + for me i guess :). And is there anything you can add to actually help me on my current problem here?

3 Replies

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

Answer by kaleetos · Jul 18, 2011 at 06:57 PM

Here is a script you can use. I did some testing but I never tried it in a full game, so no guarantees. Nevertheless read through the script. I left lots of comments to help explain whats going on.

*note to the Mods: I wasn't sure if I should take this conversation to the forum. Let me know if that is the case.

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 Shealei · Jul 18, 2011 at 08:35 PM 0
Share

Wow mate i cant believe someone actually went through so much trouble for another person. I cant show my gratitude enough. Do you an msn or a skype adress so that we can talk?

I'm trying to get it work for me. But it seems i know the problem. $$anonymous$$y center of the turret is inside the turret and the raycast doesnt get to me. It hits the turret first. I'll try to get it out and see what happens then. Even though the turret is marked "Ignore RayCast and isnt a rigidbody" i dont get why it gives me such an error. I'll keep you posted, dont go anywhere. I want to show you my gratitudes as soon as i get this to work.

avatar image
1

Answer by kaleetos · Jul 17, 2011 at 05:08 PM

For the hitmark: depends on which collision mechanism you are using for bullets. If you are using a raycast, you can use the RaycastHit.normal property to get the direction the hit came from. If you are using a physics based objects you can use the Collision.contacts property (which returns an array of ContactPoints) and get a sample of the normals from the points in that array.

As far as the screen shake, there is a project here that might help you out.

Comment
Add comment · Show 5 · 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 Shealei · Jul 17, 2011 at 06:31 PM 0
Share

Thanks again mate. I'll try to combine these variables together somehow. On my $$anonymous$$d right now is this solution. I'll create/define 4 new ractangle shaped GUI Textures and open close them for certain angles of the normal property. I am using arrays by the way, and according to you, which one is better for general purpose? I always thought arrays were a bit more optimized since it doesnt require a rigid body and kinda gets a bit weight of the CPU off. What do you think?

avatar image kaleetos · Jul 17, 2011 at 06:50 PM 0
Share

I think you mean to say you are using raycasting, not arrays. If that is the case, I do believe that raycasting is the better choice for bullets.

avatar image Shealei · Jul 17, 2011 at 10:19 PM 0
Share

Yes mate i am using raycast :). Although i still cant figure out the HitIndicator thingy, where and how to start...

avatar image Shealei · Jul 18, 2011 at 05:16 PM 0
Share

Any help anyone :(?

avatar image kaleetos · Jul 18, 2011 at 05:28 PM 0
Share

working on it right now.

avatar image
1

Answer by Bravini · Jul 17, 2011 at 05:17 PM

the camera shake effect can be done putting the animation on an empty gameobject that is parent of your camera. Just change your hierarchy from Character>Camera to Character>Shaker>Camera (put the anim on the shaker object). This way the shake occurs locally and don't affect your camera's current rotation or position

Comment
Add comment · Show 4 · 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 Shealei · Jul 17, 2011 at 06:27 PM 0
Share

Thanks alot mate, i'll try and do that now.

avatar image Bravini · Jul 17, 2011 at 11:42 PM 0
Share

no problem, and don't forget to mark the answers as accepted if they solve your problem

avatar image Shealei · Jul 18, 2011 at 03:07 PM 0
Share

You answered one part of my question i'll mark the thread green as soon as i get another answer :)

avatar image Bravini · Jul 18, 2011 at 06:49 PM 0
Share

I didn't mean just my answer hehe you can accept more than one too, so I answered the one I was certain that would work (I did that on my project) and left the dirty job to my fellow devs : ]

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

How to draw another camera's view without "Handles"-class? 0 Answers

Blender like Camera Control Shortcuts 1 Answer

How to move GUI objects to separate Camera Layer - and why? 1 Answer

I want to put main camera floating 0 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