Aligning entity to another entity?

Blitz3D Forums/Blitz3D Programming/Aligning entity to another entity?

Cubed Inc.(Posted 2013) [#1]
I've never understood how to align and entity to another entity; plain and simple. It's stupidly embarrassing for me to admit -_-
Can someone show me how something like that would work? Think how Mario 'aligns' to a planet in Mario Galaxy, for the sake of envisioning, of course.

Literally any sort of help is appreciated.


Kryzon(Posted 2013) [#2]
Aligning something to an arbitrary surface like in Mario Galaxy:



You can use something like this: http://blitzbasic.com/Community/posts.php?topic=98358#1148708 (and post #15 has the code for that).

EDIT: Actually, if you're talking about a spherical surface like in Mario Galaxy you can optimize that by using directly AlignToVector with the vector from the planet's center to the player.

vecX = Player.x - PlanetCenter.x
vecY = Player.y - PlanetCenter.y
vecZ = Player.z - PlanetCenter.z
AlignToVector(Player, vecX, vecY, vecZ, 2)

But most likely in your situation it's a surface other than spherical.


Cubed Inc.(Posted 2013) [#3]
I was thinking more of having the player face whatever surface he's touching. I overcomplicated my situation a bit.


Kryzon(Posted 2013) [#4]
Facing the surface is possible, it depends on which of the three axes you submit to AlignToVector with the 'Axis' parameter.


Polan(Posted 2013) [#5]
Well your mesh probably have normals calculated, and normals are facing outward from surface. If you want mesh to walk on surface, just align it to surface Normal.


Cubed Inc.(Posted 2013) [#6]
I've tried doing all of those things, but it either comes out with the player spazing out crazily in random directions, or zero changes at all. I'm gave the player a linepick and aligned him with PickedNX,NY,NZ on his Y-axis, but I just can't get it working. I declared the targeted surface's entitytype to comply with polygons, so I'm totally lost now. Stupid question with an obvious answer: am I doing something wrong?


Stevie G(Posted 2013) [#7]
How are you doing the linepick? Is the ray pointing straight down or is it orientated to match the players current y-axis alignment ... like so ....

Tformnormal 0,1,0,PlayerEntity, 0
Dx# = tformedx() * 50.0
Dy# = tformedy() * 50.0
Dz# = tformedz() * 50.0
Picked = Linepick(  entityx( playerentity), entityy( playerentity ), entityz( playerentity) , -Dx#, -Dy#, -Dz# )
If Picked > 0 Aligntovector Playerentity, PickedNx(), PickedNy(), PickedNz(), 2, .1



Cubed Inc.(Posted 2013) [#8]
I was trying to make it so that the ray can reach the targeted surface all around. I'm trying to make it so that the player climb a surface of any shape, like the viney bricks of a round castle pillar. In order to do that, I need the player to always face frontwards the surface he is contacted with, so he can climb it from all round.