Author Topic: Rotating an object?  (Read 1445 times)

What I want to do is rotate a flat object to the surface it hits. so
->  |
HITS and:
    )|
 V
__
HITS and:

==

Basicly I want to add this to the portal gun(Already have flat portals and better portal entering/leaving)


Aww, I was going to try that.

Anyway. The last argument of a projectile's collision is the normal it hits the surface at - 90o (perpendicular) to it, a vector of length 1.

---|
--------

Aww, I was going to try that.

Anyway. The last argument of a projectile's collision is the normal it hits the surface at - 90o (perpendicular) to it, a vector of length 1.

---|
--------
... huuuh?

Linear algebra.

The normal vector is a vector perpendicular to a plane, with Length 1 to determine orientation. Take your table for example, it's a flat plane. Now if you put a small flag on it, or a stick on a stand, that stick will be Perpendicular to the flat surface of the table (i.e. you will have a 90 degree angle to the table no matter where you measure the angle between the stick and table). Thus the line equation of your flag could be used to determine the orientation of your table.


Ok, so how would I go about applying the rotation?
I want the portal to lay against the object, so I figure I'll have to rotate it 90 degrees to achieve that, but how would I go about checking what surface it lays against? ( how would I check which value or values(x,y,z) I have to rotate it)

Try setting the rotation to (%normal SPC "0"). If that doesn't work, (%normal SPC "90"). For more info on how these rotations and normals work, refer to Wikipedia. (Two links)

Code: [Select]
function portalgunProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
 //checks for placement
 %portal = new StaticShape(){datablock = PortalBlueData;position = %pos;rotation = (%normal SPC "0");};
 //stuff
}
« Last Edit: October 28, 2007, 02:34:23 PM by Space Guy »

K thanks, I'll get back to you if it works or if I need moar help(new to manipulating this kinda stuff if you cant already tell)

Sorta works, but wont lay against a wall
Quote
-->-|

----|
instead of
---||

Ive attached the code so you can see what I did.
Also If anyone decides to look over it, I'm also having problems going through the portals(my methods are strange, and messy, if theres a better way tell me)

%obj.client.portalB = new StaticShape()
{
   position = %pos2;
   datablock = PortalB;
   scale = "4 4 0.1";
   rotation = (%normal SPC "90");
};

What happens when you try the 0 instead of the 90?

well then it doesnt work on floors or ceilings(90 works on those but not on walls and 0 works on nothing)