Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Non-code query-loop tip

veganpete
Registered User
Quote
2022-09-15 10:24:14

This simple 3-part query-loop is at the heart of all my game-nodes (player/enemy/vehicle, etc):

It's very difficult to explain what's happening but it's simple to set up, so hopefully it might be handy for some people to experiment with. Obviously I'm happy to explain/help/provide CCB examples as required.

Each loop allows conditional control over all events, rather than just triggering an action when an event occurs.

There are only 3 "gates" to pass in each of my loops: Events/Variables/Conditions

I usually attach all these loops to folder-nodes called "Controllers" to keep them all in one place and make it easier to copy/paste between nodes. (eg: folders called "Car Controller", "Helicopter Controller", "Missile Controller", etc..)

1- When [Event?], then Set [Variable].
When "W" key is pressed, Set Variable "W" =1
When "W" key is released, Set Variable "W" =0
When "S" key is pressed, Set Variable "S" =1
When "S" key is released, Set Variable "S" =0

2- If [Variable?], then Define [Condition]
Every Few seconds (5ms):
If "W"=0, If "S"=0, Set Variable "Tilt" = 0
If "W"=0, If "S"=1, Set Variable "Tilt" = -1
If "W"=1, If "S"=0, Set Variable "Tilt" = 1
If "W"=1, If "S"=1, Set Variable "Tilt" = 0

3- If [Condition?], then Do [Action]
Every Few seconds (5ms):
If "Tilt" = 0, Rotate Absolute "Model" 0,0,0, Animated 500ms.
If "Tilt" = 1, Rotate Absolute "Model" 0,0,25, Animated 500ms
If "Tilt" = -1, Rotate Absolute "Model" 0,0,-25, Animated 500ms

What it does:
1- Whenever an event happens (such as on proximity or when key is pressed/released, etc), Variables are set.
2- Every few Milli-seconds those variables are checked.
3- Only when set conditions are met, the actions are then carried out.
*The example above should tilt the helicopter model forwards/backwards only when W or S is pressed, it should not tilt if none of the keys are pressed, or if W & S keys are pressed together. You can use the loops for whatever you like, this is just one example.

Examples in my game:
Car/Helicopter/Bike models tilt/lean depending on direction of travel.
Car Wheels point in whichever direction the player is steering.
Engine sounds change depending which combination of keys are pressed.
Steering wheel turns and locks.
Music changes depending on if inside or outside a vehicle.
Camera automatically changes, depending which vehicle is active.
Missile A.I. chooses to follow target or to switch/follow it's own path instead.
Different events are triggered depending if player is being attacked or not.
Pedestrians choose where to walk next in the City.

Why use this instead of standard "on event, do action"?
I found the standard non-code method very confusing/bloated/messy/difficult to edit.
The query loop is self-contained, rather than separate actions spread over several different nodes.
The query loop waits for conditions to be met before events are carried out.
The query loop checks all related variables and conditions in a single process.
The loop continually checks for any changes in variables or conditions.
Until a specific condition is met, the loop is simply ignored/skipped.
The query loop can eliminate common conflicts between variables/conditions/actions.
The entire loop can be turned on or off by making the "controller" folder-nodes visible/hidden.
Controller nodes can be copied/pasted between nodes and edited/tweaked quickly.
Query loops are simpler to manage and understand, rather than creating a complex sequence of events.
A single query loop can be used to create either very simple or very complex events.
Multiple combinations of action/variable/condition can be included in a single query loop.


just_in_case
Moderator
Quote
2022-09-15 16:32:50

I don't know if you have steam or not, But I think it is better to write this guide on Steam Community of Copprecube, as on this forum these useful guides are going to be buried deep down as new posts come up. If you are on steam please do try to post the guide there as well.


VP
Guest
Quote
2022-09-15 19:40:09

Thanks ! Yes, I do have steam, I'll post them there too. They're only quick tips but they maybe helpful for someone for non-coding.


andgameplay
Registered User
Quote
2022-09-17 15:21:17

Hi VP, thank you so much for sharing your knowledge with us! I think it's amazing how you can do such complex things in such a simple way, using only variables! I learn a lot from the tutorials you make, I would be thankful if you could share the ccb file! Great work!


VP
Guest
Quote
2022-09-18 13:30:11

Sure thing. I'll make a ccb file as a tutorial for you.

....and if you like, I can share the entire Rebel County CCB file with you for you to examine the collision detection system, helicopter controller, missiles, aiming, car, bike etc. - just be aware that it's a bit messy and is not completed yet.


andgameplay
Registered User
Quote
2022-09-19 20:56:30

Thanks a lot VP!


veganpete
Registered User
Quote
2022-09-20 09:22:05

You're welcome!

Here's a link to the game, the cars and entire CCB/source-code file...

https://veganpete.itch.io/the-re...


andgameplay
Registered User
Quote
2022-09-21 02:21:55

Thanks VP, I'm studyng the files, it will help me a lot in future projects, thanks!


VeganPete
Guest
Quote
2022-09-21 07:25:17

You're welcome. Hopefully they can be of some help.


coa
Registered User
Quote
2022-09-21 07:39:21

making car physics and other vehicles physics is pretty complicated in my opinion i admire you doing that VP


VP
Guest
Quote
2022-09-21 08:18:16

Ah, nice one Coa. Thanks for your kind words!

I think this helicopter turned out quite well - I'm really happy with how it looks and feels at the moment.

I'm not happy with the bike yet, so I'm going to work on it a little more before I enable it in the demo. I can then start on the tank and jet-fighter.

I'm still not able to code yet, so all of the vehicles I make just use the default game character behaviour at the moment - I then tweak the movements a bit using variables. The main "no-code" thing I wish I could figure out is: "how to prevent keys being pressed at certain times", so I can add way more control to the default movements. I have found one way to do it but it's really messy and awkward: I clone the vehicle and switch between a live/dead version to enable/disable the game character behaviour.

There were a few things I did in the past which would be really good to include (car interior, steering-wheel, car-tilt etc)... but I forgot how I did them, so it takes me a while to go back and figure out how to add it back into this game. lol.

I'm learning that it's best to standardise as much of my work as early possible, so I can exported/import the, as prefabs, between projects, to save myself so much extra confusion.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "In?ernational" (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