Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Node-Based Scene Camera

Author
Message
Seppuku Arts
Moderator
19
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 10th Jun 2009 14:40 Edited at: 10th Jun 2009 14:43
Hello guys,

This code is if you want to have a cutscene camera or simply have the camera move along a path, this code could be modified for character pathfinding too. I'll try to explain how everything works too:

This is the main code - it comes with comments explaining what each set of commands are for:
MAIN PROJECT FILE

If you press 'return' you'll turn on 'looping'
If you press 'space' you'll turn off 'looping'


FUNCTIONS
For the individual functions used:

create_Node(x,y,z)



x,y,z are just for the coordinates for where you want to create it. Because I'm using 'FREEOBJECT', that means DBP gives you an object number rather than you defining one. If find it tidier. So to make this code work, you need to write something like this:

object = create_node(0,100,500)

the object will be created and the chosen object number will be stored to 'object', you'll notice I made the variable into an array in the main code above. It's best you use arrays as you'll be able to switch nodes much more easily.

The node object is essentially a sphere object created so that the camera may target it and moves itself to that position.


In the main code above, you will find you can just keep adding the line 'Create_node(x,y,z)' as many times as you like (and update the array size) that you will just have more and more nodes added to the scene without changing anything in the loop. So it makes it easy in changing your camera path.

MakeCameraCollider()



This works in the same way, only that you should only make the one, the camera collider is an object that the camera attaches itself to - so the object will manipulate the camera's position.

Try: cam = MakeCameraCollider()

'cam' will be your object number, which will be needed when it comes to collision with the node object.

UpdateCameraCollider(cam, target, node, speed)


'cam' (or 'o' in the function) is your camera object. With this function the camera will stay in the same position as its collider. The target is the object at which the camera will point itself (a target can be a node if you wanted it to be), 'node' will specify the node the camera will move to and 'speed' will be how quickly it gets there.

nodeCollision(cam, node)


It works exactly like 'object collision(obj1, obj2)', but I think having a function labelled for node collision, it'll just make it easier to refer back to. The first object should be your camera and the second a 'node'. So:

if nodeCollision( cam, object(1)) = 1 then end

This would essentially be; if the camera collides with node '1' then the game will end.

Finally; this function is not mine and my apologies for forgetting who made it originally, but it's the 'FREE OBJECT' function:

free_object()



You won't need to use this function, but my functions use it - essentially it checks what object numbers are free and returns it as a value - so: object = FreeObject() means that 'object' is the variable that will carry the 'spare' object variable.

Login to post a reply

Server time is: 2024-04-25 17:37:06
Your offset time is: 2024-04-25 17:37:06