Altering Physical Properties

This tutorial will create a simple object that uses the sprite for the beach ball. It will not have any event scripts but will show the different behaviours possible just by altering the physical properties. This tutorial is brought to you using the commands rest, accg, aero and size and the attributes responds_to_gravity, has_boundaries and carryable_by_hand.

IMPORTANT: Make sure you have no scripts in the scriptorium for the object 2 1 10000. If you have you should either change all references to 2 1 10000 in the tutorial to some other classifier that is free, or remove the scripts. Viewing and removing scripts can be achieved using the CyberLife CAOS Tool or any other tool that allows DDE communication and script injection. Refer to the author of that tool for instructions.

With the CAOS tool you can check the scriptorium by opening the scriptorium viewer from the 'view' menu. Wait for it to load and then open up the tree structure and go down the path for family 2, genus 1. If you can see an entry for species 10000 then you need to remove the scripts for it - if not you are clear to proceed!

We'll need to start by creating the object and placing it somewhere in the world, the following chunk will create a ball with default physical properties:


new: simp bal2 8 0 9000 0

setv cls2 2 1 10000

setv attr 194


If there are any of these commands you are unsure of then please check the CAOS Language Guide. But briefly what these have done is: (1) make the rest of the commands run instantly (2) create a new simple object, using the ball sprite which has 8 images starting at image number 0. This object will be positioned at image plane 9000 (front of screen) and will create it's own image gallery (3) The object created is given a unique classifier - in this case family 2 genus 1 species 10000 (4) it has attributes set that allow it to respond to gravity (+128), has boundaries (+64) and can be picked up by the hand (+2) (5) and finally it is placed into edit mode.

Once you inject this you should have a ball following the hand around - note that the hand isn't in it's usual carry mode, this is because the ball is in edit mode. Edit mode is a transient stage, at this point the ball has no awareness of the world and doesn't respond to gravity, bounce off walls or any other action that relies on knowing where it is in the world. To release the ball from edit mode you must right-click (notice it still has not fallen) and then pick up the ball as normal. Drop the ball and watch it fall - it probably wont bounce very much before coming to a rest. To alter the 'bounciness' of an object you will need to alter it's restitution - the percentage of Y velocity lost on collision - which by default is 40. What this means is that any object you create without specifying a value for rest will automatically receive a value of 40 - as in our example.

Now, to change it we can either create a new one but add the following line after the setv attr 194

setv rest x

or, change the properties of the one already in the world using the following fragment (which assumes that there is only one of these 2 1 10000 balls in the world). To inject this as a seperate fragment you will need to create a new COS file that has these lines in. CyberLife CAOS Tool is ideal for this because it allows multiple COS windows at a time. This fragment is changing a property of an object remotely - i.e. not in an event or upon creation of the object. In this way you can edit any object while it is in the game.

rtar 2 1 10000

setv rest x

In both of these cases x is the new value you want to change rest to. Lets start by making a very bouncy ball - use one of the fragments above with an x value of 1. Pick up the ball and drop it - you should notice a change in how often it bounces. Now, use one of the fragments above but give x a value of 100 - pick up the ball and drop it, it should lose all of it's Y velocity and not bounce at all.

Ok, that's enough of restitution - lets remove the balls and play with a new attribute. To remove them you can either use

enum 2 1 10000

kill targ


which will remove all objects matching the classifier family 2 genus 1 species 10000, or you can place the desired object in edit mode and hit the delete button on your keyboard. To place the object in edit mode you can either shift left-click it or use:

rtar 2 1 10000


Both of these are individual COS files and are not a part of the objects COS file (unless you create a removal chunk which destroys the object - but I wont complicate things here).

So, start by creating a new ball again with default properties.

Drop it from a height and watch it fall, the rate at which it falls is determined by it's acceleration due to gravity (accg) - which by default is 10. Change the value of accg to 2 using one of the methods above, but replacing rest with accg. Pick up the ball and drop it, now see how slowly it falls. Now change the value of accg to 100 and drop the ball again - this time it drops like a brick.

Right, next lesson. Remove your ball and create a new default one, drop it to the ground somewhere where there is space to the left and right of it (in the desert, just above the Science Kit powerup is a good place). We're going to be playing with it's aerodynamic qualities (aero) which affects the percentage of X and Y velocity lost every tick due to air resistance, by default this has a value of 20. To test the changes we're going to give the ball a shot of velocity and watch it's movement arc - inject the fragment below to launch the ball.

rtar 2 1 10000

setv vely -70

setv velx 50

If you placed the ball where I suggested it will end up close to the call button. Replace the ball back into it's starting position and change the value of aero to 1 (using the same method you used for changing both rest and accg). Reinject the fragment to give the ball velocity - and see how far it goes! This time it will have travelled to above the incubator area. Replace the ball in it's start position and change aero to 50 - relaunch it and notice the change in the arc it travels ... and also how slowly it falls. This is because it has a very high air resistance value and is getting slowed down by the air.

Remove your ball and create a new one, this time we'll be playing with the size attribute. Size is a quality which dictates which walls an object can pass through, and which ones it will bounce off - where a wall is actually any room boundary or floor. If you are in cheat mode you can use the 'show map' option to reveal all room boundaries and floors.

By default an objects size is 127. Pick up your ball and drop it in the desert, right above the lift shaft that leads down to the Science Kit powerup and cheese machine area. It will quite comfortably bounce on that floor. Now try changing the value of size to 120 - and drop it in the same area. This time it should drop all the way to the bottom. Pick it up and drop it to the left or right of the lift shaft this time, it should bounce as before. You can even throw it so that it bounces off the desert and then falls down the lift shaft. The reason for this is that in Albia all the lift shafts have a door value of 120 - this means that anything of this size or less will pass through them without colliding. Normal walls have a value of 0 - which means fully closed and nothing will pass through them. Try moving your ball around Albia and dropping it in varoius locations. You should notice that all of the lift shafts, wooden platforms and walkways will allow the ball to pass through - whereas all the walls and soil areas will stop it.

Ok, so that's the theory but why would you ever need to use this? Primarily it is used to allow insects, flying animals or seeds to pass through walls/floors that are supposed to support creatures. One example of this is the wooden walkway that crosses the great gorge - having insects colliding on the underside of this would be wrong, they are small enough to pass through - whereas you really want it to support a creature!

These physical attributes are reliant on the fact that an object has the correct values for attr set up during creation. For example, changing size will have no meaning if the object doesn't respond to boundaries in the first place - and likewise, rest, aero and accg are meaningless if the object doesn't respond to gravity.

And that's it for this lesson.