@NikRudenko Hi guys, I've been trying for a while and I've got a working magnet in BB3, it is a very classic one, it moves gems along the path toward the player when the magnet power up is active, the problem is it only works while in the first level of a world (Start), after the first level gems are no more moved toward the player but moves in different directions. Here's the code I used in the update function inside the gem object (which has no physics enabled), it should be quite self explanatory. I tried two versions, a simpler one and one involving matrixes but the result is the same. function update(dt){ if ((enabled)&&(counter<120)){ counter += 1; tractor_speed = counter/500; gemPos = this.entity().position(); //Current gem position tempVec = gemPos.sub(Settings.playerPos); //Vector to follow this.entity().setPosition(gemPos.x-tempVec.x*tractor_speed, gemPos.y-tempVec.y*tractor_speed, gemPos.z-tempVec.z*tractor_speed);}} function update(dt){ if ((enabled)&&(counter<120)){ counter += 1; tractor_speed = counter/500; gemPos = this.entity().position(); //Current gem position tempVec = gemPos.sub(Settings.playerPos); let mr = Mat4.createRotation(Settings.playerRotQuat); let mt = Mat4.createTranslation(gemPos.x, gemPos.y, gemPos.z); let m = Mat4.multiply(mt, mr); let p = new Vec3(-tempVec.x*tractor_speed, -tempVec.y*tractor_speed, -tempVec.z*tractor_speed);p = Mat4.transformPoint(m, p); this.entity().setPosition(p.x, p.y, p.z);}} Any idea of why it only works in first levels? Thanks!
So, it looks like I finally fixed it, there were two problems, first I had to consider the world position of the gem and not its space position. I tried before but not in the right way and unfortunately that misleaded me. Second: this won't work very well as it is for objects inside a Level Path but will work perfectly fine in other cases, you just have to place objects to be attracted outside of the Level Path. In such a case, the object is connected with the path and when you move it it will move along the path, so moving it in world space won't work (hope that makes sense). To improve on this it would be good to be able to understand if an object is inside a level path or not, I'm looking for a way, anybody? The code in the Magnet node will look something like this: var enabled = false; var gemPos; var gemWorldPos; var counter = 0; var id; var tractor_speed = 0.1; var tempVec = new Vec3(0,0,0); function init(){ } function update(dt){ if ((enabled)&&(counter<180)){ counter += 1; tractor_speed = counter/180; gemPos = this.entity().position(); gemWorldPos = this.entity().worldPosition(); tempVec = gemWorldPos.sub(Settings.playerWorldPos); this.entity().setPosition(gemPos.x-tempVec.x*tractor_speed, gemPos.y-tempVec.y*tractor_speed, gemPos.z-tempVec.z*tractor_speed); } } function signal(name, value){ if (value) enabled = value;} As it is it should work fine but you need to create a setting (Settings.playerWorldPos in this example) which will keeps track of your player (or other character/object) world position. If anybody is interested I can create a small simplified bbdoc to show how this works.
I dont know scripting, but can u make to also follow gem rotation to caacter like enemy face toface??
I found some error, I removed remove node and remove scrip, but after several second gems still disappeared, with big speed
I see, so you're looking for something a bit different, by the way this is just an example of how to obtain this kind of effect, it is oversimplified and far from being perfect or specific for the implementation you require; of course it could face the player any way you wish by rotating it accordingly but this require more code to be added.
@Bilz636 Hi, as i said this is an oversimplified implementation, I created this to show how to create a magnet in the most simple way, I stripped down the one I'm using heavily with the purpose of making it extremely simple and as easy as possible to understand how it works. By the way you might just go inside the magnet script and disable this line: // if (counter>60) this.emitSignal('Remove', true); (note: Adding two slashes in front of the line will disable it). This line automatically removes the gem after 60 cycles which means after 1 second, if you set attraction force very low the gem will disappear way before reaching the player. If you disable this line you'll have a tail of gems forming right behind the player. It all depends on what you wish to obtain, for example you might enable collisions and add score points when a gem is hit by the player or make it so it will deal damage or kill the player or maybe bounce away when it hits the player; there isn't any real limitation but as of now some coding is needed to get exactly what you want.
Hi @whitedogapp, I don't see how this is relevant, by the way the reason you see the gems disappearing is because in the end a gem will end up being exactly in the middle of the player since it is being attracted; try setting the player color to a transparent one by setting its alpha channel to 128 and you'll see gems stacking inside the player cube.
hello thanks for the node but i have a probleme why it doesnt work on another games ? i tried it on other games i keep getting error : TypeError: v.x is undefined any help please ?
Hi @Mrbond007, make sure inside the update function of your character's Path Move component you add this line: Settings.playerWorldPos = this.entity().worldPosition();