Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Help please

Author
Message
Fighter
21
Years of Service
User Offline
Joined: 12th Jul 2004
Location:
Posted: 21st Apr 2005 19:50
I was wondering if anyone could show me how to get past my problem.

I try to get my Cube to copy its self, I can get another cube to appear but it then comes up with an error saying Object already exists.
I think I know what happens but I don't know how to fix it. I put

If mouseclick()=1 then make object cube 2,5

I think it then loops and tries to make the object again. Please help me.
Robot
22
Years of Service
User Offline
Joined: 27th May 2004
Location:
Posted: 22nd Apr 2005 01:22
you can only have one object with the number two but what you are doing is making an object with the same number again. Try something like this.


The happenings of tommorow are behind us now
Fighter
21
Years of Service
User Offline
Joined: 12th Jul 2004
Location:
Posted: 22nd Apr 2005 19:44
ok, thanks will test it when i get home.
Fighter
21
Years of Service
User Offline
Joined: 12th Jul 2004
Location:
Posted: 25th Apr 2005 02:38
Ok got the object to appear without an error, but now I wan t the object to come to my first object when i press shift. At the moment the new object just goes along the side of the matrix.

I would post code but the internets down at my house and i have to use friends and the libraries.
NanoBrain
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 25th Apr 2005 11:00 Edited at: 25th Apr 2005 12:50
Fighter,

To get a more precise understanding of your need, do you need object B to translate(move to a location at a moment's time) to where object A is. Or, do you want object B to 'walk' to object A, gradually making its way there? Either or, I will answer both.

To make object B translate to where object A is, simply find the coordinates of object A, via OBJECT POSITION X(Object Number), OBJECT POSITION Y(Object Number), and OBJECT POSITION Z(Object Number). Then, assign these coordinates to object B, using POSITION OBJECT Object Number,X,Y,Z.

However, to make object B 'walk' to object A is a bit trickier, though simple once learned. To do this, you first need to find the angle between the two objects with the command, ATANFULL(Distance X, Distance Y). Replace Distance Y with Distance Z, to keep this consistent. Try this, ATANFULL(obj1_x# - obj2_x#,obj1_z# - obj2_z#). Now, what is left to do is make object B(obj2) follow object A(obj_1) when the spacekey is pressed.

In the code snippet below I have used cos and sin maths to make object B follow object A.



Since, we are needing to make movement on two dimensions, x and z, we must use an angle value of the third dimension, in this case the y axis. Look at figure 1. When finding movement on other dimensions, other axises' angles will be used. Look at figure 2.


Green = Z axis : Red = X axis : Blue = Y axis

If I understood math a bit more, I would explain to you why sin and cos are used where they are. However, as I did, with a little experimentation with the two, you can learn how to bridle them and use them properly. Well, in this situation at least. Cos and sin can be made to also create ellipses movement and much more. But, one must understand the two to create the proper formulas.

Here is a code snippet with source code of a runnable program for you to use, which allows the user to press the spacebar to make object B follow object A.




+NanoBrain+

Login to post a reply

Server time is: 2026-07-10 14:59:01
Your offset time is: 2026-07-10 14:59:01