In all game dev you have prototypes in the scene editor,
here we have a model prototype of the "dog" unit and the model prototype for the "spaceship" unit.
Obviously you just disable them (or leave them offstage or whatever),
and at run time when you need a Dog you clone the prototype.
Generally speaking this all works great in the Apple setting with SpriteKit - terrific. You'll have code something like ...
func setupModels() {
modelDog = self.childNode(withName: "modelDot") as! SKSpriteNode
modelSpaceship = self.childNode(withName: "modelBumper") as! ShipThing
}
Then you can clone them as needs be
But there is one hang up.
While you can isHidden a sprite, Apple really made no way to "utterly disable" a sprite, physics and all. (NB, pls don't suggest "set the collision bits" - it's a model! heh)
However I thought of a solution which (seems to) work fantastically, even though it seems strange ...
.. just remove them from the scene (!)
removeChildren(in: [modelDog, modelSpaceship])
WTF right?
This does seem to work perfectly. No, really, you can still clone them perfectly as normal during play.
Am I bonkers, is there a problem here?
Does everyone do this and my question is lame?
Since 100.0% of games use models, does Apple have a "model" setting or such I missed??
Again, my question is ..
I have an SKSpriteNode. I actually oddly remove it from the scene, it's just "sitting there" (it's .scene is nil). Is this ok?
Related
So i'm working on this project and i'm using it to finally learn how to animate in 3D (taking a small break from coding hehe)
So here i am faced with a problem and i have no idea what i did wrong. First let me explain how everything works.
So the Animator is attached to the player, and the player obviously has a structure of legs arms...etc
everything inside the player is being animated by this animator.
So i have a weapon (a wooden sword) that has it's pivot attached to it's bottom (in case it helps to know)
i'm animating it from that pivot point, which happens to be the parent to which the sword model is a child to.
When i hit the V key the weapon gets instantiated in the player's hand (which is an empty gameobject) and when i press the F key the player attack and activates a trigger in the animation that starts the attack animation.
But the animation is not working properly. more precisely the key frames of the weapon are not being player(as you can see in the video all the rotation axes give the coordinates of 0 0 0 throughout all the animation.
But, ...and this is where the strange things start!... when i manually go through each second to play the animation and see what's happening, you can see that those coordinates start to change and it shows the animation exactly as it's supposed to be. then when i switch back to idle state so that i can start moving around the player normally. when i hit the F key to attack the correct animation is player and no problem happens... Magic? i don't think so... :p
what do you think? what could be causing this problem.
Who's up to solve my riddle :cool:
Seriously guys what's going on here, i need help.o_O
Thank you all ;)
The Video : HERE
In general: You are using an ALPHA version 2019.3.0a4 ... in short don't.
As any alpha version it is like to have some bugs .. especially since you are not even using the latest instance of the alpha which afaik would be 2019.3.0a12!
2019.3.0b1 is actually even already in BETA state a lot of former bugs should be fixed there - but it is still a beta release meaning it is not ready for production.
So in general don't even use the beta. Rather stick to the latest stable release version which would now be 2019.2.3f1
There is not directly listed one relating to the animator not finding a certain object at first and then not animating it .. but as said alpha version are likely to have bugs. Also since it is an instantiated prefab the original instance will be gone .. then by name it gets re-assigned by the animator so the main issue might be that you instantiate it in the first place instead of just having it already from the beginning.
You should consider only using the parent/pivot object of that sword and not animate the sword itself at all. Simply spawn it as a child of the animated pivot and you should be fine,
I want to render two SpriteKit SKViews at the same time which share a common SKScene. I'd like each SKView to show a different part of the scene (e.g. from a different SKCameraNode). Is this possible?
What I've tried: I've instantiated two SKViews and called .presentScene(mySharedScene) on both of them. I can render those views simultaneously and animations work just fine. But since the camera position is set on the SKScene itself via the .camera property, I can't assign a different camera to each SKView.
Ultimately, I'd like to create a simple bouncing ball that leverages SpriteKit's physics engine. Each SKView will be displayed on a different physical monitor, and the ball should be able to bounce between them. I'm doing this purely as a learning exercise.
Yes, you can, I have done split screens before, but let me tell you. It is a real pain. All of your updates get called twice, so you are going to have to develop a system that works around it. Instead, for a simple experience I recommend copying your scene to your 2nd View then updating your camera to your new location.
func didFinishUpdate()
{
let copy = scene.copy()!
view2.presentScene(copy)
copy2.camera!.position = newPosition
}
I'm making my first game with Swift and SpriteKit and have noticed that my game quickly approaches 100% CPU use. I have been posting a lot about this recently, but here I'm now I'm now attempting to pull it apart to determine where my problems are. I originally thought my problem was with instantiating new enemies, so I removed everything but the small user-controlled spaceship and its shooting functionality. However, I'm still hitting 100% after a couple minutes of "play". I'm using the time-profiler instrument to try and figure out whats going on but I'm having trouble. I've broken up the time line:
Here is the first subgraph when the user clicks a homeScene button to enter the GameScene.
I'm not entirely sure what the red and yellow "Heaviest backtraces" with 3256x and 861x respectively mean, but from tutorials I've seen I would imagine that they are abnormally high. Here is the Call Tree as well:
I'm also not entirely sure why the controller textures would be using so much as they are simply setting two textures in the file right before the GameScene class:
let controllerBaseTexture = SKTextureAtlas(named:"Sprites").textureNamed("controllerBase")
let controllerHandleTexture = SKTextureAtlas(named:"Sprites").textureNamed("controllerHandle")
class GameScene: SKScene, SKPhysicsContactDelegate {
Then here is the Call Tree when the game starts and when the CPU reaches 100%:
I'm also confused about what "UnsaveMutableAddressors" are, as I see them very commonly when trying to debug this code.
I know this is a lot, but I'm not sure where to begin. Any suggestions would be awesome. I would also like to know if there are good resources on how to interpret this better because I've gone through a handful and I'm still very stuck.
Thanks for any help!
The profiler shows it's something in your update method for your gameScene. Keep in mind this gets ran around 60 times per second so you don't want to do anything extremely heavy there.
I am trying to make a function so that when the bird touches one of the pipes something should happen (which i will write down later) but right away i got an error and i don't know how to fix it.
It is "UITouch" part that gets the error I've already tried to put multiple different codes there but i don't know what i should write there.
If you know the answer please tell me. :)
func ifCollidedWith() {
if bird.touchesBegan(UITouch, withEvent: pipePair){
}
}
You can't use an SKSpriteNode to call touchesBegan. touchesBegan is a method that runs when the screen is tapped, not when a node interacts with another node. If you want to detect a collision you need to give the node a physics body. Create a enum and use that to assign category bit masks, collision bit masks and contact bit mask between your sprite nodes. This may sound confusing, so here is a guide to help you: Ray Wenderlich Swift SpriteKit for Beginners
first time posting on stack and everything looks promising so far! I had a bit of a complicated question here so I'll do my best to provide exact details of what I'd like to get accomplished. I'm working with a third person controller in unity, so far everything is going great. I've dabbled with basic up and down platforms, a little glitchy but things work. Anytime my player runs through a mesh I make sure the mesh collider is working and a 'rigid-body' is attached set to Kinematic. Here's the kicker, in my game I have turning gears which the player can jump on. This is great except for the player doesn't turn with my gear, which would make sense according to my game-play. What would be the process for getting my character to interact with this animated mesh? I imagine some sort of script which my nooby mind cannot fathom at this point in my unity career. If anyone out there knows the solution to this, I would love to have any assistance, either way I'll plugging away at a solution. Thanks again!!
This is assuming that you're using the packages that ship with Unity3D, which it sounds like you are. After importing the Character Controllers package, you'll have a bunch of scripts in the Standard Assets\Character Controllers\Sources\Scripts folder, in the project hierarchy view. There's a script in there called CharacterMotor.js, attach that to the same GameObject you're running ThirdPersonController on.
Essentially this script adds more interactivity between the character and the scene. There's several methods inside this script that automatically move the character when in contact with a moving object (as long as it has a collision mesh) basically by inheriting the object's velocity.
If your gear/cog wheel has a proper collision mesh set up, adding this script to your character should be all that you require.