Aligning to vertexes under 90 degrees?

Blitz3D Forums/Blitz3D Programming/Aligning to vertexes under 90 degrees?

Cubed Inc.(Posted 2013) [#1]
Sounds like a strange question, but I actually have a useful programming method in mind. I was thinking to make it so that the player of my platforming game aligns to the world when touching it (see banjo-kazooie or Mario 64 for reference) and if the angle of the vertex collided with is over 90 degrees (an upright wall) it would not align to it, ergo, it would not "run up it". In addition, if the angle of the player is over 70 degrees (a high, steep slope) the player would be programmed to slide down the slope as if he lost traction (once again, just like in banjo-kazooie and Mario 64). Can anyone help me out? Any help is greatly appreciated.


Matty(Posted 2013) [#2]
Yes - calculate the collision normal or the picked normal directly down from the player's position then normalise the vector and compare the length of the y component .. if it is less than a certain value then the angle is too steep.


Kryzon(Posted 2013) [#3]
It's overkill to align the character to the terrain. It won't look natural - when you're walking on a slope it's your feet that align to it, not your body (you need to stay upright for balance).

The games you cited don't align to the ground; Since we're always moving in those games, we don't even notice it. Here's a screen:


Even though the character lies in a slope, he remains upright (to the detriment of realism as you can see his left foot piercing the ground).
In the middle of gameplay we don't pay attention to that: we're immersed in the game and take as standard such fake things, like the pixelized trees behind him.


They do use steepness to shift the character to "slide mode", when you lose control and the character slides down until reaching a walkable slope such as the ground (the ground is also a slope; It's one with zero elevation).
I suggest you use a LinePick instead of Collisions to get the normal. You can certify that the LinePick will always be cast against the ground, while collisions might be reported against other directions such as when frontally hitting walls etc.


Cubed Inc.(Posted 2013) [#4]
I've always had trouble understanding Linepick. Can you explain the function to me? Like how it works exactly. Also, can you refresh me on normals in Blitz3d context? I'm sorry if it seems like I'm asking for too much, but from what I've heard the function is quite useful.


Matty(Posted 2013) [#5]
Function GetSlope#(ent)
;check slope
;ent = player entity for example

;linepick checks for the first obstacle met from the position specified in the first
;3 parameters in the direction of a vector specified in the next 3 parameters. There is also
;an optional parameter to say whether the 'pick' is a thin ray or has a specific radius.



	if linepick(entityx(ent,0),entityy(ent,0),entityz(ent,0),0,-10000.0,0) then
		
		return 1.0 - pickedny() ;pickedny() should give the normal vector's y component 
	else
		return 1.0
	endif
End Function

;;in your game somewhere...

if GetSlope(playerentity) > slopetolerance# then
	;Player is unable to walk up this hill for example
else
	;Player is able to walk up this hill...
endif  





Edit - that was typed without having blitz in front of me so hopefully the syntax is correct. (Been a while since I've done any blitz programming too)


Cubed Inc.(Posted 2013) [#6]
So let me see if I got this right : The "pick" function in Blitz3d is supposed to recognize the parameters of an entity's vertexes. So if the player is constantly recognizing these parameters, and, lets just say, pickedNY = 0 on a flat surface and 1 on a slanted one, then that could be used to create the "steep sliding" effect. Am I on the right track, or am I just confusing myself even more?


RemiD(Posted 2013) [#7]

The "pick" function in Blitz3d is supposed to recognize the parameters of an entity's vertexes.



From my understanding and tests :
The linepick function return either 0 or the reference of a picked entity/mesh.
This entity/mesh must be set to pickable before using the linepick.
If a entity/mesh is picked, then you can retrieve some infos :
The coordinates X,Y,Z of the picked point.
The normals NX,NY,NZ of the triangle at picked point.
The reference of the picked entity
The reference of the picked surface.
The index of the picked triangle.

The picked normal is the normal of the picked triangle.

Once you know the normal Y of the picked triangle, you know how steep is the slope and with this you can decide how to make your character behave.

Instead of aligning the character on the slope, another approach would be to have different movements and different animations depending on the slope.


Kryzon(Posted 2013) [#8]
@TaGames: read my posts in this thread: http://blitzbasic.com/Community/posts.php?topic=98358