What does the variable localFront refer to in the function look(at:up:localFront:)?
I am trying to get my SCNCamera to look at an SCNNode. I understand what at and up refer to, but cannot find any information about localFront.
It refers to where you want the eyes to be of the object you make look at something, which is normally the localFront property of the node you are looking with (i,e. the camera node). In case where you use it for other nodes than the camera, it can be used to make an object point towars another object with another “side” than its front. For example, you could have a car that you want its side to look at (line up with) the side of another car. Or you could have an evil monster with eyes in front an in the back of its head so it can look at something from both sides :)
Related
I have this lamp object. And i marked with a red circle the part i want to cut and make as a different object. Only the yellow part i want to make it object. So i can later use it in the game is object and also as item.
This is the lamp inspector:
Create a prefab of the lamp object and export it as a unity package.
You can then import it in other project as Custom package.
Source : https://docs.unity3d.com/Manual/HOWTO-exportpackage.html
Depending on the type of the model u have (obj, fbx etc) u need to go to 3d Modelling software like Blender or Max to modify the model. There u would be able to do any change to model u would like to including diving in too and maybe changing of shapes! Once done u can import them back into unity and have two different objects!
Taking the model into max as suggested would be the right idea. You'll likely take it in as an FBX.
Once you seperate the lamp from the post you may want to affect it's pivot.
For MAX look here
Be careful when exporting out the fbx again. I have noted that it seems to be best to export the model back out in metres. Automatic unit conversion may give unwanted results.
I'm following the tutorial: http://www.raywenderlich.com/80586/make-line-drawing-game-sprite-kit-swift#
All is going well except that each one of the 'pig' child nodes from the Pig class all move together; in that when I draw a line for one node all the nodes follow the same path. If I then draw a line for another node, they all then follow that one.
What I'm trying to work out is how to make each pig node follow it's own path.
I've tried naming the nodes 'pig1', 'pig2' etc, while 'touches begin' does show specifically which node I'm touching, it seems the line path when created for one pig is applied to all and not each individual pig node.
I've contacted the author but with no reply, I would greatly appreciate any advice, be it another tutorial (can't find any myself).
Thanks
Apologies, despite thinking I was following the code correctly, I stupidly made the wayPoints array (which held the line coordinates) a global var for the Pig class instead of a object (node) specific.
Changed position of var declaration and all is good.
Ive seen a few questions similar to mine but I can't get it working for my particular need.
I have 2 scripts both in unityscript, EnemyHealth.js and BasicAI.js . In EnemyHealth.js I have an int variable called Health. I want to pass this over as a variable within BasicAI.js so that I can check whether the enemies health is below a certain range. Both scripts are attached to a game object 'Enemy'.
The second part of my question is, if var Health is below a certain amount (say, 20) I want a function flee() to be called. How would I make the enemy turn away from the player and proceed to move away ?
Thanks.
To answer the first part of your question, you'd want to use (GetComponent)[http://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html]. What this does is lets you get other scripts on a GameObject of a particular type. In your case, you'd be doing something like:
var enemyHealth = gameObject.GetComponent(EnemyHealth);
Then you'd just need a public way to access the variable called Health, whether that variable is public or there is some sort of getter that is public (if you don't want BasicAI altering health, then you'd want to go the getter route instead of just making the variable public).
Now, as to make the enemy flee, that's a pretty complicated question that involves a number of things and I think it might be a bit too broad to answer in general. Might want to look up some basic AI scripting to get a handle on those concepts.
There is various ways to call another script in Unity. Either GetComponent as Brett said but I would use FindObjectsOfType (http://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html) in your case.
The AI question is pretty unclear. Do you already have a AI that does something? Just to call the flee method just type what you said in your question (probably in Update(http://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html).
if(Health < 20){
flee();
}
How do you add a CIPixellate Core Image Filter to a Sprite Kit scene?
I have a SpriteKit scene that is an SKScene or subclass of it.
I want to add a Core Image filter to the scene. Specifically a CIPixellate filter, so I can have 8-bit game heaven for free.
How do I do that?
It turns out this is not hard at all. It's just that the Core Image Filter docs are OLD and crufty and in the case of SpriteKit, the docs are flat out misleading or incomplete, including the SKEffectNode docs.
The SKEffectNode docs have this to say (as of this post) on the filter property of SKEffectNode:
The Core Image filter must have a single inputImage parameter and produce a single outputImage parameter. The default value is nil. If
the value is nil and the effect node is enabled, no filtering takes
place. However, its children are still rendered in a separate pass and
blended to the parent’s framebuffer.
Well that's sort of informative, but not terribly informative, because the Core Image Filter catalog says CIPixellate has the following keys for parameters:
inputImage
inputCenter
inputScale
It doesn't say anything about an outputImage or that the inputScale is "how pixellated".
Well, that's that... let's look at how to.
First off, note that SKScene inherits from SKEffectNode.
That means you can add CIFilters to it. Awesome.
All you need to do is this.
First create a CIFilter.
CIFilter *pixellateFilter;
pixellateFilter = [CIFilter filterWithName:#"CIPixellate"];
[pixellateFilter setDefaults]; // Remember to setDefaults...
// We could change some value but for this one we won't.
// [pixellateFilter setValue:#(10.0) forKey:#"inputScale"];
Then configure your SKEffectNode to actually render effects!.
[aScene setShouldEnableEffects:YES];
It's not a bad idea to center the filter. But your mileage may vary.
[aScene setShouldCenterFilter:YES];
Next add the filter.
[aScene setFilter:pixellateFilter];
Note that you can add this before or after it is added to a parent node and before or after it is on screen. You can even build custom SKActions to do this... :)
From all of this, one thing you can note is that the Core Image Filter catalog, as old as it is, does tell you that various filters are members of various CICategory types, even though those are poorly documented as well. But you can basically assume that anything that works in a given category implies that other filters in that category might also work :)
I am making a graphically simple 3D game in C++ using DirectX. The main problem I am having is with how to structure some things efficiently. Right now I know my goal for certain areas but not how to ideally perform them.
For instance, right now I am storing all meshes and textures in an Asset class with enumerated definitions pointing to each asset. All meshes and textures are loaded when the game starts by creating an Asset object and initializing it. From there I load meshes and textures to objects by assigning the pointer given by the Asset object. Is this the best way to go about this?
A harder topic is that of items. For the sake of argument I am going to say we are dealing with scenery. Right now my scenery needs the following:
A name
A mesh
Textures (optional)
Flags (such as Destructible, Flammable, etc.)
Status (such as Burning, Locked, Cursed, etc.)
Abilities (things the object actually does, such as becoming damaged when burning)
The first 5 things on this list are simply variables. But abilities are bothering me. The first 5 can all exist in one item class. But what I do not know how to do is somehow attach abilities to the object.
For example; I want the object to have the "Fire Nova" ability. At the start of each turn, the object damages anything near it.
For me, this means each object would need a "Trigger_Phase_TurnStart()" or some similarly named method and would then need a new "Fire Nova" class with its own unique action for that trigger and its own extra variables (Damage, Range, etc). So now I have the base object class and a new Fire Nova class that inherits from it.
But now what if I needed an object that has Fire Nova and Frost Nova and also Slowing Aura and other such abilities. Basically I need a way to add triggered effects to an object without needing a new object class for each of them.
So by the end I would be able to have say:
(pseudo code of the object's components)
name = Elemental Orb
mesh = "Mesh_Sphere"
textures[] = "Tex_Ice", "Tex_Fire"
flags = OF_Destructible
status = SF_Cursed | SF_Burning
abilities[] = Fire_Nova, Frost_Nova, Slowing_Aura
And this orb would simply be the object class with all these attributes. The object would then activate each stored ability's trigger at the appropriate turn phase for any actions to perform.
Right now I am thinking I might need to make a class for each ability possessing every turn-phase or action trigger (inherited from a base ability class) and have them perform the appropriate action when the object calls them from it's array of abilities. Would this be the best way to do this?
As a separate issue. Some flags would require additional variables that would otherwise be unnecessary. For example, Destructible would mean the object would have health whereas without the flag it wouldn't need it, or an Openable item would need an array of contents. What would be a good way to ration these variables to when they are needed? I do not need every wall to have health and an empty contents array for example.
Finally. Assuming the bullet-listed attributes above are all an item needs, how might you suggest I best store them? To clarify, I would like to be able to write:
CreateItem(ITEM_CHAIR);
and have this return the created object with name, mesh, textures, flags, status and abilities. What structure might be suitable for achieving such an end effect?
To summarise:
Does my current Asset storage seem feasible?
What is the best way to create abilities to attach to the object class without making numerous separate object classes?
Is there a way to limit the variables (or at least memory usage) when the associated flag is not present?
What structure or format would be best for storing fixed item definitions?
Sorry if this is a little long winded. If you cannot answer all the questions then an answer to one would still be appreciated. Question two is probably the largest priority for me right now.
Thanks for your time :)
I want only answer question 2 and it looks like you need a decorator pattern. In OOP a decorator pattern is useful when you have many ingredients and wants to decorate an object, for example a pizza. Unfortunately you need to create for each ingredient a separate class hence I think you have the right approach. The good thing is that with the decorator pattern you can wrap the object over and over with abilites classes and call only one method at the end to do all the stuff.