Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Spawn object on click

moonchristmas
Registered User
Quote
2022-10-15 17:51:05

Hi! I’m very new to Coppercube and am having some trouble with what I think would be a pretty basic function.

I’m trying to build a clicker game where one of the main mechanics will be clicking on a node that will spawn a basic physics object like a sphere out of a chute. I have the node click part working and tied it to a variable that can display the total number of clicks. I can get an existing sphere on the map to clone itself on its current location when I click the node, but can’t figure out a good way to have the sphere spawn at a particular spawn location or a way to have it exist on the map outside of the play area and then move it to the chute location as a clone after the click. I thought maybe treating it like a bullet and having the spawner shoot it out would work but the shoot action seems to remove the sphere’s physics properties so that doesn’t really work.

All I can seem to make work is cloning the sphere at its current location, which makes using the original sphere as the spawn point for others difficult when I want to immediately apply physics to it so it will roll out of a chute.

Any advice on how this could be approached would be appreciated!


Guest
Guest
Quote
2022-10-16 02:52:08

You can create a spawn point by taking a cube or whatever and scaling it down to 0. Rename it to something suitable. Then in your "Clone a scene node" action --> "Action to do with clone" do: "Change position of a scene node". In the "Change Position of a scene node" action you can set the position type to "Set relative to a scene node". "Change which scene node" can be set to the current scene node, and the "Relative to which scene node" is whatever you named your spawn point. Hopefully this helps.


moonchristmas
Registered User
Quote
2022-10-16 17:34:14

Thanks for responding! I had tried the above suggestion, but it comes up with the same issue. The clone continues to spawn on the original object.

My best guess is that the physics simulation on the cloned object is getting in the way, because when I remove the physics property from the object, it does as expected and translating the clone to the spawner works just fine, except of course now it's an object without physics so it just sits there at the spawner, rather than drop with gravity and follow the physics as I need it to.

Is there any way of activating physics on a particular object that passes through a trigger maybe? Since I don't know the code side, I'm not sure how to accomplish this with just the behaviour/action interface.


moonchristmas
Registered User
Quote
2022-10-16 17:42:28

For reference, when I keep everything as suggested and physics on the cloned object and have it animate to new position, it will fly toward the spawner, then when it reaches it, immediately disappears and transports back to the original object to appear.


Guest
Guest
Quote
2022-10-16 19:04:48

I pretty much only write code for my projects, so this may or may not work. Try using the "Reset behavior of a scene node" action after you change the position of the scene node to the spawn point. It's under Game and Sound. Another thing you can try is "Execute Java Script" action and just put:

ccbUpdatePhysicsGeometry();

From the CC documentation:

ccbUpdatePhysicsGeometry()

Note: This function is not available in the editor.

Updates the collision geometry of the physics simulation. Call this when you modified the static geometry of the world and want the physics simulation to respect that. This only works when physics simulation is turned on and available for the current platform.


Guest
Guest
Quote
2022-10-16 19:06:58

One more thing I just thought of after posting: do you have the collision turned off on the spawn point? That probably needs to be done if not.


Guest
Guest
Quote
2022-10-16 23:51:37

I decided to make a sample project to see if I could fix your problem. Unfortunately I couldn't get it to work with default CC behaviors and actions. None of the solutions above worked either. The code in the JS file isn't very complex, but feel free to ask any questions if you need to do so. Maybe Vegan Pete (VP) will see this post and tell you a way to do it with visual scripting only. He seems to be the expert here on that. Here's the link to the project:

https://ufile.io/rf0z1pea


moonchristmas
Registered User
Quote
2022-10-17 00:39:34

Thank you for making the effort! I just tried both of the above solutions and couldn't make it happen either. Wasn't positive that I was calling the javascript line at the right point in the command order (I had it call in the same action place as when I was calling the clone to move to the spawn point, wasn't sure where else to put it or what order things get executed in CC).

But yeah, I've even tried to get creative and find ways to physically block the original object in the space so it acts like a static spawn node and just let it kinda shoot out the new clones, but that's reliably led to various issues with collision.

I'll keep messing around, but it seems like it probably needs a more complex code solution than I can do with the visual scripting.


Guest
Guest
Quote
2022-10-17 01:27:53

The sample project (ccb file and all) I posted does work, however. Not sure if I was clear about that in my last post. It clones a ball (with physics) at the spawn point when you click the cube (switch) and then rolls on the floor when it drops. I just couldn't do it with CC's visual scripting. If you should have any more questions, feel free to ask. Cheers!


moonchristmas
Registered User
Quote
2022-10-17 03:47:28

Oh no I didn't realize that. I'll try it out just as soon as I can go through the apparently pretty elaborate hassle of convincing Windows the download isn't a virus haha


Guest
Guest
Quote
2022-10-17 04:39:00

It's probably the site I used to upload the file. I looked it up on VirusTotal and 2 out of 89 security vendors flagged it as malicious. That's pretty much nothing, but just in case you have trouble downloading it still, here's a catbox link:

https://files.catbox.moe/rr41n9....

The file is only 3.2 mbs on both ufile and catbox.

Let me know if you need any help with the code.


moonchristmas
Registered User
Quote
2022-10-17 15:18:52

Ok yeah that works exactly as needed, thanks!

I think I vaguely understand the code for now, but I'll need to make multiple spawners eventually and call for spawns at different intervals and with different materials, so I'm sure I'll be back with more questions later.


moonchristmas
Registered User
Quote
2022-10-17 22:58:49

I am actually now having a related physics issue after getting some other things working. I have a room built from the basic static geometry made with the in-engine room maker. I'm trying to allow a trigger to switch that room out with a nearly identical room that has modified geometry (in this case, it goes from a flat floor, to one with a pit for the balls to fall into), but none of solutions seem to respect the geometry, it treats it like the floor is still flat.

I've tried:
- hiding/unhiding the floor
- deleting the original node entirely
- moving the original node to another location
- deleting the node and running the ccbUpdatePhysicsGeometry() command in a js

Seems like a similar issue to before, where CC just does not enjoy changing physics stuff while the game is running. Although if that's the case, I'm not sure how you're supposed to manage really basic stuff like moving doors, invisible walls, etc. other than with physics turned off.


moonchristmas
Registered User
Quote
2022-10-17 23:07:10

Interestingly, updating physics geometry as part of a command to do every few seconds (I'm doing 10 milliseconds) did work, mostly. Physics objects already on the ground that was being removed stayed hovering until interacted with, but new objects fall properly, so that's something at least.


Guest
Guest
Quote
2022-10-18 06:25:16

So I worked on your problem a bit and added to that project I already sent you. I have not messed with CC's physics stuff much because I forget it even exists because it's buried in the menus. That said, there seems to be an issue where the collision only updates if the ball is in motion. So if the ball is moving, it drops when the floor is change, but if it is NOT moving, then you are pretty much out of luck. My crude solution for this was to drop another ball on it with an alpha (it's green in the example so you can see it) texture when you hit the switch to change the floor. Luckily the ball that sticks seems to be in the same position at all times apparently. Like I said this is a crude solution but it should work. My experience with CC so far is you kind of have to build your game idea around its limitations. A more elegant solution for this could be to identify the coordinates of the position where the ball is sticking and change the geometry so it works better. Here's the link to the project:

https://files.catbox.moe/1mgfbd....


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact