- Home /
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.
I want a HitMark like Crysis and CoD indicating where i am hit from on the screen, fashing red rectangles.
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.
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.
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?
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.
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.
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.
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?
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.
Yes mate i am using raycast :). Although i still cant figure out the HitIndicator thingy, where and how to start...
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
no problem, and don't forget to mark the answers as accepted if they solve your problem
You answered one part of my question i'll mark the thread green as soon as i get another answer :)
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 : ]