on giant’s shoulder-task2, different weapon mode

task:
Weapons script – Fire() is called when this weapon is selected and the corresponding button is pressed.
This is what will be called when a player pulls a trigger(in this case left and right mouse button for now) and this weapon is selected. There should be several things that can be set in this:
TYPE:
Blind-fire (does it just shoot a rocket straight where you aim),
Lock-On (requires a lock on of an enemy(make a fake enemy for testing) and fires a tracking object, this one will be probably the toughest),
Fake-fire(does not create an object but does damage to an enemy if they are being aimed at, think lasers, machine guns, and maybe a better name)
RANGE:
for Lock-On and Fake fire only
DAMAGE:
-For fake fire only
AMMO:
remaining or infinite
Any more you think would be awesome.
——————————————————
well well. not seems so hard.
1.blind fire is just what i’ve done, shoot some stupid bullets and let it fly forward.
2.fake fire need to play an anim or whatever( i use a light) and make raycast:
Physics.Raycast(transform.position+transform.forward*0.8f, transform.TransformDirection (Vector3.forward),out hit,range)
this will return true if hit something.
don’t forget out before hit. hit is a “RaycastHit”, and need to be used like “it.collider.GetComponent<Health>()”
light is add below weapon, in shoot, laserShotLight.intensity = flashIntensity; to make it light, in update, laserShotLight.intensity = Mathf.Lerp(laserShotLight.intensity, 0f, fadeSpeed * Time.deltaTime); to make it fade
3.lock fire. tough one.first need to lock thing with mouse. then need to make the bullet find the target.
the first one, we can make a ray of mouse:Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
the second one, “transform.LookAt(target);
rigidbody.AddForce(transform.forward * 100);”
looks simple when you know how to do it. but still cost me some time to make it work 😦
4.clean the code.
we can always get some component in the same level use getComponentInParent. and use gameObject can get the object the component rely on( useful when i need to destroy the object in script).
gameObject.transform.root can get toppest thing. it is strange i can’t get player in script in arm by “gameObject.transform.parent.parent”, but can get it by this root magic words.
This entry was posted in on giant shoulder and tagged . Bookmark the permalink.

Leave a comment