I’m sure people hate it when a newb spews out a bunch of questions, but I have 14 pages open with enough tabs on each page to make it have the → arrow because all the tabs can’t be shown at once.
I have a lot on my mind and can’t find out where to start. People are always so fast to point to a tutorial page that is semi-related, but doesn’t work in the end. I am not great but not terrible at modeling/rigging/animating things, but I don’t know much about scripting etc. My questions are…
How do I make a script relate to anyone and not just the one player I choose. For example, the TornadoTwins tutorial for the Worminator game thing has a “Turret” that always aims at and fires at the player defined in the code. Is there a way to change that to be based on any “Player” tagged thing?
How would I go about setting a range at which something happens? For example, player gets close to an enemy, causing the enemy to start chasing/attacking or something.
How are scripts differentiated between objects? I want to know because I want to be able to make generalized scripts like movement, attacking, AI/waypoint systems… but… only have it apply to certain things. My game will hopefully be multiplayer someday, so I can’t have one person control all the players, so how can I separate everything? In the last game engine I used, it was like there was 1 big general script and each enemy could extend from it and it ended up being very confusing at times. That brings me to the next part…
Is it bad to just toss in a mesh/enemy and attach a bunch of scripts like… one for Health, Damage, Movement, AI, Experience points, Item drops etc… The method of 1 big script can be frustrating/difficult, but would a bunch of minor reusable scripts be bad for performance?
How can I call an animation with a keypress. I looked on the forums and saw examples, but they don’t work for me. For example, I want to press the left mouse button and have it call the “Attack1” animation I have with my character. Every time I tried I got errors, usually telling me I need to place a { or }… but when I do it tells me it was unexpected or something.
How can I tell an event to go along with an animation? For example, if the player is doing the “Attack1” animation, have the sword apply damage to “enemy” objects. It has to match the animation because I don’t want to cause damage with a weapon if I’m not actually attacking. I believe this would be a box collider/trigger thing, but that is the next one…
What are triggers and how do they apply things? I saw someone talking about a melee/sword system, which I am very interested in… and someone else said to add a box collider and make it a trigger or something. I added a box to a sword and put it in the characters hand. I saw that the only thing was a check box for “Trigger”. I was expecting more like a script I could enter to the trigger to call an event, like damage or something.
Tags. What are they? Would all players be “Player” tag and enemy objects be “Enemy” tag? I was wondering about this because I was going to have a variety of enemy types and didn’t want to generalize them all. For example, a zombie. You can never go wrong with having zombies. Zombie = Enemy tag, but how would I classify it as Undead? Or would I have it classified as Undead tag and have all the scripts for damage have a different number for each tag?
This is only a segment of my questions, because they are the earlier stages of my game. I know most people don’t like to just come out and say stuff, but I have spent a few days straight with just about no progress on my game because I can’t seem to get things to work my way. I am in need of help. I want to get the basics set up for combat in my game, as it will be an important feature. Once I get the basic layout, I can customize it more until it is just how I want it. Eventually I will add an experience/level system, equipment/inventory and a class system, but that is in the future. I’m not asking for people to make my game for me, I just need to know what some things are. Unity is way different than other game engines… and although it seems much easier… it still evades me for the most part. If some more-advanced Unity user than myself could spare some time to help me, PM me with an AIM, MSN or Steam ID, because it is easier than using this. Thanks to anyone in advance. Any help is much appreciated. I can’t help others much, but I’m going to make a bunch of simple model types like… guns, swords… maybe a zombie here or there… and put it online for others to use. I’m going to try to put up some basic scripts with comments and some models so people can just download it and have a basic layout for different game types to modify. Starting from scratch can be difficult. Once again, thanks in advance. Good luck to all~
I have a few individual posts about problems, but they don’t get useful responses either. What I don’t get is if people have a really complex problem, groups of people start going at it, but when someone has a more general problem, it gets far less attention. My questions are kind of inter-related too… It’s more of me trying to get a guideline of how to do things as I go along, not just a piece here and there, because sometimes down the line it doesn’t work together properly.
1-3 - this is a modified code of this TT-tutorial. caution: the turret turns is ALL directions (360°xyz) - this isn´t fixed atm
var damp =40;
var LaserPrefab: Transform;
var savedTime = 0;
var speed = 30;
var seeDistance:float = 70;
function Update ()
{
var LookAtTarget : GameObject;
LookAtTarget = GameObject.FindWithTag("Player");
var thePlayer:GameObject = LookAtTarget;
var distToPlayer = Vector3.Distance(thePlayer.transform.position,transform.position);
if (distToPlayer <= seeDistance)
{
var rotate = Quaternion.LookRotation(thePlayer.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
//print ("in range");
var interval:int = Time.time;
var oddeven = (interval/2);
if(oddeven)
{
Shoot(interval);
}
}
// else
//print ("out of range");
}
function Shoot(interval)
{
if(interval != savedTime)
{
var laser = Instantiate(LaserPrefab, transform.Find("turretSpawnPoint").transform.position,transform.rotation);
laser.rigidbody.AddForce(transform.forward * speed);
savedTime=interval;
}
}
you can connect scripts without using static vars… findbytag(where your script is attached to)… getcomponent(“scriptname”); you´ll find some example in the forums.
but you always have to use ScriptName.YourVarFrom ThisScript
for example: a laser hits the player
//attached to the enemy laser prefab
var lifetime: float = 3.5;
var Dmg:float;
static var EnemyLaserDmg:float; //amount of dmg
function Awake ()
{
EnemyLaserDmg = Dmg;
gravity = 0.0;
mass = 0.0;
drag = 0.0;
collider.isTrigger = true;
Destroy(gameObject,lifetime);
}
function OnTriggerEnter (hit : Collider)
{
if(hit.gameObject.tag == "Player" || "astroid")
Destroy(gameObject);
}
//..somewhere in my player script
function OnTriggerEnter (hit : Collider)
{
if(hit.gameObject.tag == "enemylaser")
MyEnergy -= Enemy_kill_projectile.EnemyLaserDmg;
}
you wrote something about animations… maybe you´ve forgotten to set your frames in the inspector for the animation which you want to request. for example animation x from 0 to 100 - the script requests “animation x” and plays 0-100…caution: unity doesn´t recognize that there is an animation or even a lenght of an animation…this is something you need to set up by yourself.
I’ve kind of been distracted and away from the forums, but thanks for the reply. I’ve figured out a couple of my questions, but most of the time… if I have time at all… I’ve been making little models to spruce up my map. Scripting is tough and I have no grasp of it… I mainly just want to get a basic prototype of my game and maybe get some followers. Meh… I’ll mess with those pieces of script when I have the free time. Thanks~