Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Normals question
Topic Started: Feb 25 2009, 01:20 AM (823 Views)
saijee
Elite Member
[ *  *  *  * ]
A few questions about normals.

I have read a bit about the lower section on collision on the manual.

But I don't really understand it much.

First off, one thing I'm doing is making shadow's in a way similar to that of N64, a simple blackish gray circle on the floor completely flat, I would like to know how to make the circle angled the same way that the normal is angled. Like so:
http://www.colourlovers.com/uploads/2007/05/n64_super_mario_64_start.jpg

Second off, I would like to know how to find the ID of the instance of a normal. I'm making a platformer game similar to Super Mario 64, and you know, platformers are all about platforms.
Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
Replace your shadow with an arrow so you can align the shadow correctly. It should either be a model facing north or a wall primitive when you're finished.

Check these in the manual.
ComputeMatrixRotationAngles(..)
CalculateVectorLongitude(.)
CalculateVectorLatitude(.)

Any chance of your Youtube videos landing on this community soon?
Blog|EHS
Offline Profile Quote Post Goto Top
 
saijee
Elite Member
[ *  *  *  * ]
Ok, I read that part in the manual, now It kinda makes sense, but I cannot try it out right now, because I'm letting my brother borrow my computer for today. I'll try it this afternoon...

On a side note, gee would it really be OK to put the video up on this community? I mean...Where would I put it?
Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
Dunno. Wips or Off Topic? Or just have people wonder about this conversation and have them find it for themselves. XD
Blog|EHS
Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
About the shadow, this has been answered before, and a good solution to your shadow problem (which was posted in that topic) was to do like this:
create a plane with a transparent circle shadow texture on it and then use this code in the step event of your player object:
Code:
 

shadow.x = player.x;
shadow.y = player.y;
shadow.z = player.z;

shadow.dis = CheckRayIntersection(all,shadow.x,shadow.y,player.z,90,0);
shadow.ray_norm = GetRayTracingNormal(-1);

with(shadow)
{
roty=point_direction(0,0,GetVector(ray_norm,1),GetVector(ray_norm,2))+90;
rotx=radtodeg(-arcsin(GetVector(ray_norm,3)))+90;

ReleaseVector(ray_norm);

Step();
}

You have to fiddle around with the roation values yourself to fit your levels, but this should work fine for most terrains.
Edited by Despellanion, Feb 25 2009, 06:38 PM.
Offline Profile Quote Post Goto Top
 
saijee
Elite Member
[ *  *  *  * ]
Sorry I forgot about that topic, but anyway, how about that other question?

How would I return the instance ID of the model of the normal?
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
saijee
Feb 26 2009, 01:42 AM
How would I return the instance ID of the model of the normal?
Same answer as I gave here, since this comes down to finding the ID of the model that was intersected first by the ray specified in the preceding call to CheckRayIntersection(...).
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
saijee
Elite Member
[ *  *  *  * ]
Wait... How would that look like in code? I got lost for what I'm supposed to be looking at...
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
saijee
Feb 26 2009, 11:51 PM
Wait... How would that look like in code? I got lost for what I'm supposed to be looking at...
If your platforms are all instances of the same object, you can use a "with" statement. Otherwise, you could add the different platform ID's to a list/array and use a for-loop to cycle through them.
In either case, you will also need to find out which of the platforms is closest to the ray origin.

In case you're working with instances of the same platform object, try this in the Step Event of your character:
Code:
 
var X,Y,Z,Normal,Closeness,Dist,Closest;

X=x;
Y=y;
Z=z;
Normal=CreateVector(-1,0,0,0);
Closeness=90000;
//cycle through all platforms, to find the one directly under the character
with (platform)
{
Dist=CheckRayIntersection(id,X,Y,Z,90,0);
if (Dist < Closeness)
{
Closeness=Dist;
Closest=id;
GetRayTracingNormal(Normal);
}
}

//if any platforms were found to be under the character, do something with
//the one directly beneath the character and/or its normal vector
if (Closeness < 90000)
{
//do stuff with the Closest platform and/or the corresponding Normal
}

ReleaseVector(Normal);


In the other case, replace the "with" statement with a for-loop to cycle through the platform ID's, stored within a ds_list (you could also use an array) which you defined earlier:
Code:
 
PlatformCount=ds_list_size(my_platforms);
for (i=0; i < PlatformCount; i+=1)
{
Platform=ds_list_find_value(my_platforms,i);
Dist=CheckRayIntersection(Platform,x,y,z,90,0);
if (Dist < Closeness)
{
Closeness=Dist;
Closest=Platform;
GetRayTracingNormal(Normal);
}
}
.
.
.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
saijee
Elite Member
[ *  *  *  * ]
A few more questions. 1 Would it be ok to have 2 as a value instead of -1 for CreateVector?

2 Is there a way to get the roty value of a face? this part is not really necessary, But In some parts of my game it is a 2D platformer in terms of gameplay. And I'd like to make it to where the level can be shaped differeantly then just a strait path, to make it look more interesting.

Like in Paper Mario:
http://www.youtube.com/watch?v=4xbrmmwrTtU&feature=related

Notice how the room's are usually not box shaped but take the shape of part of a tube.

Another example is klonoa.

http://www.youtube.com/watch?v=d6RXvCUNX-4

If there is a way to get this kind of thing going on I think players would find the game a lot more fun, even though it does not affect the game play, it would feel more fun.
Edited by saijee, Mar 1 2009, 10:08 PM.
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
saijee
Mar 1 2009, 10:08 PM
1 Would it be ok to have 2 as a value instead of -1 for CreateVector?
When you create a new vector, you have to use a negative value, so it would be OK to use -2, but not 2. Positive numbers would be interpreted as the ID of an existing vector (one that was created using a negative value previously), which is usually not what you want.

Quote:
 
2 Is there a way to get the roty value of a face?
You can only find the orientation of a face, relative to its normal. The roty is the same as the latitude of the normal vector, while rotx is the longitude of the normal + 90 degrees:
Code:
 
triangle_rotx=CalculateVectorLongitude(Normal)+90;
triangle_roty=CalculateVectorLatitude(Normal);
This is another alternative for aligning the shadow of your character to the terrain, but it won't help for keeping the character on a curved path.

One solution you can try, is to create a copy of the path geometry and use it to map its curvature to its local height, so ray tracing can then be used to derive its curvature from its height at any point.
Okay, let me explain all that in more detail.
1) In your modelling program, create a copy of the path geometry.
2) Make sure that the "internal" edges of the path (as opposed to the side edges) are as perpendicular to the curvature as possible. For example, if part of the path is a circle arc, the edges should point to the centre of that circle.
3) Set the height of those edges to match their direction (latitude).
For example, if an edge has a latitude of 20 degrees, you set its height to 20 units. If the angle value is 83, set it to a height of 83, etc.
Avoid negative values.
3) In U3D, make sure that the modified path copy is vertically aligned with the original path, and add it to a room that is not rendered by the camera (using SetObjectRoom(...)).
4) Trace a ray from the character's x/y location, with the z-coordinate being the lowest point of the duplicated path. Trace the ray upwards to the path copy and the returned distance will equal the roty value needed for your character.

NOTE: the topology of the original path and that of the copy don't have to match perfectly. Just see to it that the copy covers the original completely, and that it's sufficiently subdivided to allow smooth angle interpolation.

To show you that it does indeed work, download this example.
To make the kart move, press the up/down arrow keys, and you'll see that it follows the curvature of the track quite nicely. After a few laps the kart does tend to get off the track, but the model from which the angles are derived could probably be improved, and you can always allow manual corrections by the player I guess.

Anyway, I hope this will help.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
saijee
Elite Member
[ *  *  *  * ]
Well, if I did say -1, then wouldn't I be creating a new vector every step? Wouldn't it get to the point that the game slows down?


About aligning with the path. I took a good look at it... Then asked myself "Is it possible that this could be done by using the wall instead of the path itself?

Like Could I make the character Always move in a direction parallel to that of the angle of the wall, and if the player is a certain distance away from a givin distance, the it will attempted to move on track again.

Know what I'm saying?

Oh another question, How would I check if a wall is completely vertical with no angle? See it's a platformer, and I want to have a wall jump feature, I always loved those things.

Edit----

Also to that last one, I want to know how to find out if the angle to a floor is so steep that it is actually a wall, so the object can recognized that it's getting to the point that it will just slide down.
Edited by saijee, Mar 3 2009, 02:12 AM.
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
saijee
Mar 3 2009, 12:42 AM
Well, if I did say -1, then wouldn't I be creating a new vector every step? Wouldn't it get to the point that the game slows down?
You can create a vector in the Create Event and store its ID in a local variable, so you can re-use the same vector every step. In that case, you only need to release the vector in the Destroy Event. Ideally that's how it should be done for each vector, although sometimes it can be easier to just create and release a vector in the same piece of code (I usually do that in my code examples to make them easier to read).

Before I answer the rest, I'd like to know if you intend to use varying curvature for the path, or will it be purely circular, like in the vids? In the latter case, you could actually use simple trig to keep the player on the path:
Code:
 
//adjust the angle of the player, based on his distance from the centre
//of the path arc (radius), his current speed, and whether the wall is
//at his left (side_facing==-1) or at his right (side_facing==1)
roty+=side_facing*arcsin(speed2/(2*radius))*180/pi;
Move(0,roty,speed2);

Quote:
 
About aligning with the path. I took a good look at it... Then asked myself "Is it possible that this could be done by using the wall instead of the path itself?

Like Could I make the character Always move in a direction parallel to that of the angle of the wall, and if the player is a certain distance away from a givin distance, the it will attempted to move on track again.
Your idea seems more obvious than the example I posted yesterday, but I think both solutions will eventually need some additional collision handling to keep the player on the path.
Anyway, to make your suggestion work, you would cast a ray to the left or right of the character (depending on which side of the character is facing the wall), and set the character's roty to the latitude of the normal +/- 90 degrees:
Code:
 
var Dist;

//check distance to wall at the left or right of the player (given by
//side_facing, which is either -1 or 1)
Dist=CheckRayIntersection(walls,x,y,z+hip_height,0,roty+90*side_facing);
//re-use normal_vect (created in Create Event) to store the new normal
GetRayTracingNormal(normal_vect);
roty=CalculateVectorLatitude(normal_vect)+90*side_facing;

There's another problem I anticipate here, though: while the player is passing a corner, his angle would alternate between those of both sides of that corner, which would look a bit weird. To remedy that, a second ray would be needed, so the corresponding normals can be averaged. This would require additional vector math, and I'm not even certain it would solve the issue completely.

Quote:
 
How would I check if a wall is completely vertical with no angle?

Code:
 
//if wall is not at an angle...
if (CalculateVectorLatitude(normal_vect) == 0)
{
//...do stuff
}

Quote:
 
I want to know how to find out if the angle to a floor is so steep that it is actually a wall

Code:
 
//if surface is steep enough...
if (abs(CalculateVectorLongitude(normal_vect)) < 20)
{
//...treat it as a wall
}
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
saijee
Elite Member
[ *  *  *  * ]
I'm a bit busy to actually try to put that code into effect. But It's basically the same as the shadow facing floor thing right? except 90 degrees to the side.

Here is an illustration I made though of how I envision it working.
Posted Image

Thanks for the response though.

Also, is creating/destroying vectors every step faster or slower then just creating one at creation and destroying it at destruction?

Also you can assign the vector to a different normal right? Sorry, I'm only half way done taking Algebra 2, not yet into trig yet...
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
saijee
Mar 4 2009, 02:12 AM
It's basically the same as the shadow facing floor thing right? except 90 degrees to the side.
Yeah that's the idea.

Quote:
 
Here is an illustration I made though of how I envision it working.
Okay, so you want to chamfer sharp corners for smoother movement. It would definitely help, but wouldn't solve the issue completely I think.
And there's still the problem of how to correct the position/angle when the player leaves the path.

Anyway, I believe I have a very good solution now :) . Please download my improved Curved Path Example, which will allow you to keep the player on a perfectly smooth path at all times. I didn't want to point you to that example before, as it was hard to implement additional actions, like jumping, turning around, etc..

Now that I made some important changes, it should be much more flexible and I hope you'll find it useful.

With this example, you can create any kind of path you want, save it as a text file, and load it into your game. This path consists of smoothly connected circle arcs, whose curvature you can control. This should allow you to approximate the path in your game pretty accurately. Read the online help (F1) very carefully to find out how to create your own paths.

You should import a completely flat version of the path geometry into the example (stairs and other elevations would cause problems - you can use raytracing in your game to set the player to the correct height) and place it at the exact same coordinates that you have your in-game path at. Then you can start placing waypoints to shape the path curvature.
Getting the shape right may take some practice, but once you have that the hardest part is over. Some complex math is going on in the 4 user scripts (just import "CurvedPath.gml"), but you don't have to worry about any of it. Only the starting comments and the ending of MoveToWaypoint(...) need your attention. It explains what variables to set up for what objects, and it's here that you can further adjust the transformation values of the player (just before Step() is called). That's where you would set the correct height for example.

Quote:
 
is creating/destroying vectors every step faster or slower then just creating one at creation and destroying it at destruction?
The fewer function/external calls the better, so just creating a vector once is more efficient than re-creating it every step.
Quote:
 
Also you can assign the vector to a different normal right?
You can redefine a created vector, if that's what you mean? Like, you can assign the result of a vector sum to one of those vectors:
Code:
 
var Vect1,Vect2;

Vect1=CreateVector(-1,5,-3,4);
Vect2=CreateVector(-1,1.5,7,9);
//redefine Vect1 as the sum of Vect1 and Vect2:
CalculateVectorSum(Vect1,Vect1,Vect2);
//instead of creating a new vector for the sum:
//VectSum=CalculateVectorSum(-1,Vect1,Vect2);


EDIT: There was a mistake in the MoveToWaypoint(...) user script of the Curved Path Example and I've removed the need to add the required local variables manually, so please download the example again (link above is updated).
Edited by MysteriXYZ, Mar 6 2009, 06:48 PM.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
ZetaBoards - Free Forum Hosting
Free Forums. Reliable service with over 8 years of experience.
Learn More · Register for Free
Go to Next Page
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply