Zaba
Jun 28 2006, 04:55 PM
Hey, im creating a flash 3d game. i wanna this:
camera follows mouse,
ASDW control,
Space as jumping,
world.
1 and 3 are MAIN problems.
HEEELPP!
In other words, i want basic phisics:
if not touching ground
vspeed++
else
vspeed=0
if jumping
vspeed = 20
Help me please asap!
kiroukou
Jun 28 2006, 05:06 PM
Hi,
Did you tried something?
I can help you to correct your code, or to give you the best solution to a specific problem, but I can't do the job for you.
What
you needs seems feasible to me. Camera follows mouse is quite easy, and
the basic physics engine can be done if you implement some physics
tests of the objects vertex!
++
Zaba
Jun 28 2006, 05:22 PM
i done it all in 2d already. a month ago. is there a way to port 2d
code to pseudo3d, huh. im first day at sandy, im gonna experiment with
other (p00r) 3d engines before. no idea about hitTest in 3d yet... btw
im kinda new to Math3d things. ;-)
EDIT: yay i done something (movement for/back)
Zaba
Jun 28 2006, 05:38 PM
Look at this
its flash8
the problem is i want to hop on and stay at box
Zaba
Jun 28 2006, 05:56 PM
Jumping is done for 1/3
:-S
point me to my mistake... hope ull notice it... try to jump (Space)
kiroukou
Jun 28 2006, 06:19 PM
Not nice but working code :
CODE
import sandy.core.light.*;
import sandy.core.data.*;
import sandy.core.group.*;
import sandy.primitive.*;
import sandy.view.*;
import sandy.core.*;
import sandy.skin.*;
import sandy.util.*;
import sandy.core.transform.*;
import sandy.events.*;
var vspeed = 0;
// screen creation, the object where objects will be displayed.
var ecran:ClipScreen = new ClipScreen(this.createEmptyMovieClip('ecran', 1), 600, 600);
// we create our camera
var cam:Camera3D = new Camera3D(700, ecran);
// we add the camera to the world
World3D.getInstance().addCamera(cam);
//We create the Light coming from the left with a low intensity (20)
var l:Light3D = new Light3D(new Vector(1, 0, 0), 20);
// set the world light
World3D.getInstance().setLight(l);
// we create the root node.
var bg:Group = new Group();
// and set it as the root node of the world.
World3D.getInstance().setRootGroup(bg);
// and we launch the scene creation
createScene(bg);
// and now that everything is created, we can launch the world rendering.
World3D.getInstance().render();
function createScene(bg:Group):Void {
//
We create our object. It is a cube of 50 pixels, and with the quad
mode, so here four points per face.
var o:Object3D = new Box(50, 50, 50, 'quad');
// we create a skin to "dress up " the object a bit, and make it visually better.
// SimpleColor skin is used here, it needs the fill color, alpha, and thickness
var skin:Skin = new MixedSkin(0x00FF00, 100, 0, 1);
// NEW PART, we enable the light
skin.setLightingEnable(true);
// We apply the skin to the object
o.setSkin(skin);
//
We create two TransformGroup instances. Each one corresponds to a node
of the tree we are going to create.
var tg1:TransformGroup = new TransformGroup();
var tg2:TransformGroup = new TransformGroup();
// We also create two instances of Translation objects.
// Give them an appropriate name, this becomes important very rapidly.
var translation:Transform3D = new Transform3D();
// We create an interpolator to make it rotate linearly for a while
var ease:Ease = new Ease();
ease.linear();
var rotint:RotationInterpolator = new RotationInterpolator(tg2, ease.create(), 300);
// we translate the object by 500 pixels on the Z axis.
translation.translate(0, 0, 500);
// We apply those transformations to the nodes.
tg1.setTransform(translation);
tg2.addChild(rotint);
// We add the rotation tansformation to the node which represents the rotation,by setting it as a child.
// The rotation will be applied first, translation later (higher in the tree)
tg2.addChild(o);
// Now we link the two nodes
// The order here is very important.
tg1.addChild(tg2);
// Now we simply link the translation node to the root node, thus completing the tree creation
bg.addChild(tg1);
}
var ljmp = false;
onEnterFrame = function(){
if(Key.isDown(Key.UP)){
cam.moveForward(10);
}
if(Key.isDown(Key.DOWN)){
cam.moveForward(-10);
}
if(Key.isDown(Key.RIGHT)){
cam.rotateAxis(0, 1, 0, 3);
}
if(Key.isDown(Key.LEFT)){
cam.rotateAxis(0, 1, 0, -3);
}
if(ljmp && cam.getPosition().y > 0 ){
vspeed --;
} else if (ljmp && cam.getPosition().y <= 0 )
{
vspeed = 0;
ljmp = false;
}
if(Key.isDown(Key.SPACE) && !ljmp){
vspeed = 20;
ljmp = true;
}
cam.moveVertically(vspeed);
trace(cam.getPosition().y);
trace(vspeed);
}
onMouseMove = function(){
var nx = _root._xmouse;
var ny = _root._ymouse;
}
++
Zaba
Jun 28 2006, 06:22 PM
THANq
now problem is hittesting, no idea yet :-(
a huge for-in around all Object3Ds? no i think.
other ideas ? no, too...
Zaba
Jun 28 2006, 07:21 PM
read things on guide layer
I wanna hittest in 3d
help me with it
please.
kiroukou
Jun 28 2006, 07:58 PM
Hey Zaba,
you
can't ask some help and have somebody giving you the answer immediatly!
Please take time for think about the problem yourself, ask for some
precise problems!
We have all a personnal life, we are not living on that board
Zaba
Jun 29 2006, 06:09 AM
Im living with computer.
Ive thinked about it and i have NO idea...
thats why im here!
kiroukou
Jun 29 2006, 06:56 AM
Well,
For example, you did't say which king of collision test do you want.
Is it floor against object? object/object? object / camera?
You see? How can we help you if the problem isn't described correctly

But
this is a complicated part! You should do some research and some tests
! And also be patient because this will take some time for sure if you
want to do it correcly.
++
Zaba
Jun 29 2006, 07:02 AM
I need to make camera stay on floor, be able to hop on and stay to any
surface. floor is an object too, btw. and not to walk into surfaces,
like walls.
simply, camera must collide to all objects.
Zaba
Jun 29 2006, 07:18 AM
huh, it does jump better now...
Zaba
Jun 29 2006, 12:03 PM
Im dumb in Math, btw.
thats why im asking you.
kiroukou
Jun 29 2006, 12:24 PM
Well I'm sorry but I have a lot of work curently and some others projects (developing Sandy take a lot of time).
So I'm sorry, I'm not able to code anything for you. I just can give you the good orientation to do that.
Retrieve
the surfaces, compute their equation (easy to do with the normal
vector), and then make a collision test with a 3D point, or a 3D
segment.
Otherwise you should learn some math basics! This is not very funny to do, but so usefull
Zaba
Jun 29 2006, 12:40 PM
Well, i have other 2D projects too.
But
asap please -v it. :-( im too silly and non-english to understand it
from 1 sentence... sorry if im very annoying here. but if i have 3
boxes with different Y and X ill need to check all of them? ill learn
math i think, i *hope* i will... but for now i cant so im here asking
you and others (i think).
Camera here, Camera steps here, so ill need to check only point under camera? how to get it (point) then?
>>>>| >>>> |
+--------+
|---------|+------+
|---------|--------|
+--------+-------+
Thanq for help.
Read/reply asap.
PS: the best is to make a Game Tutorial.
PPS: what a good forum you have
Zaba
Jun 29 2006, 01:16 PM
I suck (this totally slows down it):
CODE
var nx = mt._xmouse/250;
var ny = mt._ymouse/250;
for(var i in bg.getChildList()){
if(bg.getChildList()[i].isParent()){
rlist.push(bg.getChildList()[i]);
} else {
//collision detection
//bg.getChildList()[i]. ...
}
}
for(var i in rlist){
//collision detection:
//this[rlist[i]]. ...
}
kiroukou
Jun 29 2006, 02:07 PM
Good start!
But you should before try to retrieve the Leaf objects, and more precisely the Object3D instances!
You can do a loop like this but test current_node instanceof Object3D, and if true, push it into your array list.
++
Zaba
Jun 29 2006, 03:36 PM
well as i said this code will slow it down really, so it will be good
to know whats under the camera and chect only that point. My code cant
parse big worlds, but as i planned them too i think i should try other
methods... looparound all objects is bad, isnt it?
ill try what ure suggesting anyway.
thanks
by
the way... im already using isParent(), so only groups can be a parents
or not? isnt it = instanceof Group? ant can Groups contain something
another than Object3Ds? or im wrong?
Zaba
Jun 29 2006, 04:45 PM
you meant this, right?
CODE
var nx = mt._xmouse/250;
var ny = mt._ymouse/250;
for(var i in bg.getChildList()){
if(bg.getChildList()[i].isParent()){
if(bg.getChildList()[i]
instanceof Object3D) rlist.push(bg.getChildList()[i]);
} else {
//collision detection
//bg.getChildList()[i]. ...
}
}
for(var i in rlist){
//collision detection:
//this[rlist[i]]. ...
}
PS: who needs PHP here?
Zaba
Jun 29 2006, 05:47 PM
Hey,
how to get X of Object3D 8-S
i gonna be dumb...
kiroukou
Jun 29 2006, 06:02 PM
An object3D does not have an x in Sandy!
As an object is in fact composed by faces, and not as an object, you do have an position property!
But I'm thinking on a workaround to allows you to get this position!
I'll try it, and include it in the update I'll do this week I hope.
Thnaks for this question.
++
Zaba
Jun 29 2006, 06:04 PM
huh, i used getZBounds, ill need getXBounds too!
Zaba
Jun 30 2006, 06:50 PM
hm. i think all i need for basic collision detection is to get a face,
get its points, get camera pos and test for collision? cant i write a
hitTest3d(Object3D, Camera) method and use it?
kiroukou
Jun 30 2006, 06:52 PM
Yes or to use the bounds of the object indeed.
It is not very accurate, but enought I guess for a simple game.
I'll implement it!
Zaba
Jun 30 2006, 06:59 PM
oh thank you!

bounds isnt accurate as tiles could be only cubes then

no tiles at all = the best...
I sure ill be able to improve it when ill need something more advanced.
why dont you like Face checking?
im not plannng to create a simple game, but a story-based FPS (gpled of course)
kiroukou
Jun 30 2006, 07:00 PM
Face checking needs a lot of computations, imagine that you'll have to
compute the distance between the cam pos, to all the vertex of the
object.
With the bounds object, Bounding Box, you just have to compute the distance from 8 vertex!
So very useful with complex object
Zaba
Jun 30 2006, 07:02 PM
but if the object isnt a cube, what to do then?
kiroukou
Jun 30 2006, 07:02 PM
What do you mean, a Sprite?
Zaba
Jun 30 2006, 07:03 PM
i meant Sphere or a Pyramid
kiroukou
Jun 30 2006, 07:10 PM
Yes so instead of testing the important number of vertices og those
objects, you'll jsut have to check the 8 vertices of the Bounding Box
object!
So 8 tests instead of 50 per frame, this can be useful
Zaba
Jun 30 2006, 07:15 PM
ehm... i didnt get the point. if i have a pyramid theres no difference between walking over it and its bonding box???
kiroukou
Jun 30 2006, 07:19 PM
The Bounding box is the volume that encapsulate (don't know the right word) your object.
If
you are testing a cube or a pyramid, this is not useful (because of the
number of vertices), and with a cone or a sphere it starts to become
necessary!
For sure testing the Bounding Box is less accurate,
but allows you to save some computations. The result should enough for
your game.
Zaba
Jun 30 2006, 07:24 PM
QUOTE(kiroukou @ Jun 30 2006, 11:19 PM)

The Bounding box is the volume that encapsulate (don't know the right word) your object.
If
you are testing a cube or a pyramid, this is not useful (because of the
number of vertices), and with a cone or a sphere it starts to become
necessary!
For sure testing the Bounding Box is less accurate,
but allows you to save some computations. The result should enough for
your game.
im not sure.
ill need complex maps i think.
if ill use bounding box for huge pyramid ill not be able to walk on it as on real pyramid?
kiroukou
Jun 30 2006, 07:38 PM
You want to walk on a pyramid face?
You're optimitic

So indeed in this case you can use it. You should use Bounding Box just to avoid collision.
But I think your project is too complex for this version of Flash... maybe in AS3..?
Zaba
Jul 1 2006, 07:00 AM
AS3? noo ill wait for 2007 to use nonalpha nonbeta version.
lets experiment with faces now.
Zaba
Jul 1 2006, 11:25 AM
how to get camera's rotation?
kiroukou
Jul 1 2006, 03:59 PM
You can't.
Is it useful for you to be able to obtain the camera rotation?
Zaba
Jul 1 2006, 04:48 PM
yeah. to make it NOT to rotate on Z
kiroukou
Jul 1 2006, 05:11 PM
Just do the correct rotatios to make it NOT rotate around Z axis no?
Zaba
Jul 1 2006, 05:54 PM
im rotating X and Y according to mouse but it starts rotation Z in a while (why)?
any solutions?
kiroukou
Jul 1 2006, 06:00 PM
It is possible. Depends on your code.
But I had also this problem, si maybe it is a bug, but in this case, I have some problems to be able to solve this one.
Zaba
Jul 1 2006, 06:03 PM
here is it ull see comment before it
ahem.
cant it be sloved in nonsandy level?
Zaba
Jul 2 2006, 06:11 AM
i have an idea.
why not to first check bounding boxes then check object(s) that are colliding on BB level by faces?
Zaba
Jul 2 2006, 08:00 AM
hitTest3d(group:Group, x, y, z);
that shud be enuf.
as i said in prevous post, it will be great.
kiroukou
Jul 2 2006, 08:39 AM
Please do it

I will not do it myself !
This is an open source project, that means that people should make some contributions!
Zaba
Jul 14 2006, 06:52 AM
ahem.
if i would be able to do that i wouldnt come to here.
and yeah. i dont even kno:
what getBounds returns?
am i able to get camera/Object3d pos?
ill get some faces from obj3d, what i can do with em? i cant get points!
then maybe ill do something.
Zaba
Jul 14 2006, 08:04 AM
im not asking u to do it but to help me.
Zaba
Jul 14 2006, 04:32 PM
QUOTE(Zaba @ Jul 1 2006, 09:54 PM)

im rotating X and Y according to mouse but it starts rotation Z in a while (why)?
any solutions?
I got the problem, it occurs in any 3d engine (Shockwave3D for example)
i think ill think around it so thats not the problem now.
Zaba
Jul 14 2006, 05:40 PM
will not really work, the question is in comment.
Sketch:
function hitTest3d(g:Group, x, y, z){
for(var i in g.getChildList()){
if(g.getChildList()[i].getBounds()[0]
>= x && g.getChildList()[i].getBounds()[1] <= x
&& g.getChildList()[i].getBounds()[2] >= y &&
g.getChildList()[i].getBounds()[3] <= y/*Z here too?*/){
for(var j in bg.getChildList()[i].getFaces()){
//What to do with face?
trace(bg.getChildList()[i].getFaces()[j]);
}
}
}
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.