Game Development Community

Scripting Different Collision Behaviours

by Aiden Fry · in Game Design and Creative Issues · 11/29/2011 (11:38 am) · 2 replies

Hey all,

I'm new to Torque2D, and still only using the demo version, but its looking great!

Anyway hope this isn't too much of a nuubie question...

How do I script different collision behaviors depending on the objects in the collision?

This is what i'm aiming to do:

1-I want to create loads of different coloured balls and place them within the level (check)
2-The player will be in control of one object and be able to move that object around freely (check)
3-Each ball will bounce of the other balls and player (check)

now...
4-I want balls of the same colour (will be grouped by class/name) to act sticky/attractive towards each other, with the players aiming to separating out all balls into groups of their own colours, then move these bigger balls into target areas.

I would like to specify an attractive force, to that connected balls, properly coerced can, be split apart.
And all connected balls must still be able to move.

I have a feeling this is going to do with the function ::onCollision(blah, blah)
but im afraid I am pretty clueless.maybe some function call like setCollisionBehaviour(attractive)

Ideas?

Also on a similar note, is there a comprehensive list/reference for the inbuilt torque script functions? right now i'm scanning tutorials trying to find function calls that I want.

And finally, any suggestions for a good script editor for torque script (win or mac)?

Thanks one and all.
Aiden

About the author


#1
11/30/2011 (11:08 am)
I am basing this off of a gravitational field that has a certain radius of how powerful it is.

You will most likely have to update this constantly.

First you have the find the direction vector to each of the objects in question. Then you have to add that to the object's velocity and scale it based on how much force you want.

Is this what you are going for? A bit rusty on this but I believe this is what you need to do.

docs.garagegames.com/it2d/official/ Click on References and you will get a list of objects and functions and you can determine which ones you need.
#2
12/02/2011 (1:17 am)
yeah that sounds like the kinda thing i need to be doing. Cheers!