Hi guy i was thinking making a game like…Oblivion.
So i need help with a script…a sword script.I wanted my sword when i click “Fire”
Animation plays.and if i the sword collides it damages an object…
Have you tried looking at the documentation. You mentioned 2 things that have code in the docs that will help you alot “animation” and “collides” (or collider) Look at the links below, they should help you immensely.
That doesn’t help me alot cause i need when my sword hits any object it makes damage…
Thats where OnCollisionEnter comes in. (the second link)
ok Dman
And you know a script for a collider like I attached my axe that has collider . but as soon as i start moving it starts flying…Can you help me with taht.
My character starts flying…
the Axe should be parented to the node of the hand. Past that, things flying are controller issues. Post the code which controls your character and your Axe.
The only way anyone can figure this stuff out is if you post some code to look at. And make sure it’s the right code.
I’ve got only this.I just started working on it
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController]
What I would do is parent an empty gameobject with a collider (roughly the same size and shape as the axe) to the axe, put a script on it that handles the damage value and sends the damage message to the enemy in OnCollisionEnter(). In Start(), you’d probably want to use Physics.IgnoreCollision between the player collider and the axe’s collider to keep from hurting yourself and causing general physics wonkiness. Oh, and in OnCollisionEnter(), deactivate the gameObject after the damage message is sent so you can’t damage the same enemy multiple times with one swing.
Then put a script on the player that sets the axe collider object to inactive by default, and on Fire input, play the swing animation, activate the collider object to for the duration of the swing animation, then deactivate it again.
I see a basic problem.
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
This part tells the character controller that when you press (and hold) the Jump key, start moving your character up. consider using Input.GetButtonDown.
Next This part bugs me…
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
for two reasons. One: the flags is a variable which returns the type CollisionFlags this is not a true or false, this is a variable. Looking at the documentation. it should read like this:
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = flags == CollisionFlags.Below;
// or
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = controller.isGrounded;
guys i still have a proble i attached this code to my weapon and when it hits a cube nothing happends.Cause i’m so stupid about scripting can someone please write me a script and tell me what to do with it… Please this is the code i attached
// A grenade
// - instantiates a explosion prefab when hitting a surface
// - then destroys itself
var explosionPrefab : Transform;
function OnCollisionEnter(collision : Collision) {
// Rotate the object so that the y-axis faces along the normal of the surface
var contact : ContactPoint = collision.contacts[0];
var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal);
var pos : Vector3 = contact.point;
Instantiate(explosionPrefab, pos, rot);
// Destroy the projectile
Destroy (gameObject);
}
Facepalm.
For one, does the axe have a collider? For two, does the cube have a collider? For three, your script means: “anything that hits the object will make it explode”, is this what you want, or do you need to add an “if” statement in there to catch only the object with the name “Axe” or the tag “weapon”?
The grenade code is meant to be attached to the grenade, so that if it touches anything it explodes. You clearly don’t want your axe to explode.
Your not stupid about code, you just don’t know how to use it yet.
I get the feeling that he’s just posting random snippets of code from the docs to attempt to give the illusion that he actually tried coding something himself, in the hopes that someone will do it for him.
i know the grenade script did but if any thing he mite be moding the scripts he finds. i know i do. i can’t wright one or fully understand the code, but i can mod so it will work the way i wont it to.
I wish to raise some awareness… It looks like 3DKnight and ryan could benifit from this post.
http://forum.unity3d.com/threads/77844-Nobody-can-do-this?p=503243&viewfull=1#post503243
Visit this http://answers.unity3d.com/questions/8504/how-do-i-make-a-fighting-system-like-in-oblivion i found it very helpful