Giving an actor two collisions?
by Caleb Child · in Torque Game Builder · 10/24/2011 (10:52 am) · 2 replies
Since apparently nobody knows anything about how to adjust the size of a sprite's collision, my next idea for allowing a player to crouch is to have two collision hulls, one on top of the other. When the player crouches either the upper collision is ignored, or it simply is lowered into the space where the lower collision is held, whichever is easier.
To pull this off I imagine the easiest thing to do would be to create a blank sprite and attach it to the player sprite. The collision on the main player sprite is set to the lower collision, and the collision on the invisible sprite covers the upper area of collision.
But I am at a loss as to how I get the game to respond to both collision hulls. They both need to block the player if it collides with the world, they both need to generate the same reaction with enemies and attacks, and all without doubling the reactions so that the player is not damaged twice.
My programming skills are poor, and I am unsure how to pull this off. But let's start with linking the two objects. All the code written for the player's control and input are basically tied in with %this, and likewise the secondary actor would be tied in with its own %this. There are global variables that could be used, but using those would make multiplayer modes be stupid hard to set up.
How can I send variables-- no, how can I directly send commands and functions from one actor to another? How do I have an event with one of the actors directly trigger something in the code for the other actor?
To pull this off I imagine the easiest thing to do would be to create a blank sprite and attach it to the player sprite. The collision on the main player sprite is set to the lower collision, and the collision on the invisible sprite covers the upper area of collision.
But I am at a loss as to how I get the game to respond to both collision hulls. They both need to block the player if it collides with the world, they both need to generate the same reaction with enemies and attacks, and all without doubling the reactions so that the player is not damaged twice.
My programming skills are poor, and I am unsure how to pull this off. But let's start with linking the two objects. All the code written for the player's control and input are basically tied in with %this, and likewise the secondary actor would be tied in with its own %this. There are global variables that could be used, but using those would make multiplayer modes be stupid hard to set up.
How can I send variables-- no, how can I directly send commands and functions from one actor to another? How do I have an event with one of the actors directly trigger something in the code for the other actor?
About the author
http://calebchild.boldlygoingnowhere.org/caleb/
#2
So I assume the syntax go like...
Correct me if I'm wrong.
Man, this forum needs to let me give rep to people's posts; that was very helpful to me and you in fact answered both of my questions!
10/24/2011 (9:10 pm)
Ahh, so I can write code that reassigns the collision of that object. That would work so much easier.So I assume the syntax go like...
%this.CollisionPolyList = -0.5 -0.25 -0.5 0.75 0.5 0.75 0.5 -0.25;which gives a square from -0.5 to 0.5 in x and -0.25 to 0.75 in Y (Roughly the standing collision of my character, from memory.)
Correct me if I'm wrong.
Man, this forum needs to let me give rep to people's posts; that was very helpful to me and you in fact answered both of my questions!
Torque Owner Justin Proffitt
Anyways, if you wanted to adjust the shape of the collision polygon without messing with the sprite, you should be able to just assert a new list of coordinates a la Object.CollisionPolyList = x1 y1 x2 y2 etc.; Then simply remember to reassert the original value when the object stops crouching.
Now if you wanted one function/callback from one object to trigger another function/callback, you could simply call one on the other object from within the first, for instance:
function object1::doSomething(%this){ object2.doSomethingElse(); } function object2::doSomethingElse(%this){ //code }