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 Professional Discussion / "roll towards" with adv. 3d math?

Author
Message
Inflictive
14
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 21st Dec 2011 20:57
Hi, I've been trying make a function to roll an object towards a point. What I mean is, use the roll object left and roll object right commands to spin an object on it's local z axis so it faces up toward a point(or line).

Here is something terrible I am using now:



Basically this function does what I want, except it only rotates to the nearest 45 degrees. I need a function that rotates it to the exact angle, and be more efficient than this. I was looking at the 3dmaths commands, since that's probably where you'd start, and I am totally lost...

chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 21st Dec 2011 21:30 Edited at: 21st Dec 2011 21:31
I'm sure you know the point object command, so I guess you want to do something like point object but snaping exactly every 45 degrees ?
Cheers.

Inflictive
14
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 21st Dec 2011 23:31
No not really...
The point object command points it with the global x and y axises, I want it to point with the local z axis. The attached code does that but snaps to 45 degrees, I don't want it to snap.

chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Dec 2011 00:01
I don't know exactly what you need with local z axis ....could you make a diagram of what you want ? I will try to help you if I can.


Cheers.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 22nd Dec 2011 00:21
I posted a rolling marble game in the 2 line challenge.



The rolling's not perfect, it's more like a rolling wheel than a marble, but it might give you some ideas.
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Dec 2011 00:38
@29 games
Nice marbles, and the movements looks real !! . I made something like that with my rolling ball.



Cheers.

Inflictive
14
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 22nd Dec 2011 03:27
Ok, I can see that my descriptions don't make sense. Hopefully this attached image should. I have been trying for like 5 hours to do this without 3dmaths, but that's probably what you need to do it right. I don't understand 3dmaths...

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Dec 2011 10:16
I just re-read this and I see what you are trying to do now.

I would:
1-Save the angle of the object
2-Use the "point object" command to aim at the point
3-Get the difference between the angles
4-Set the angle of the object to part way in between each loop until it's close enough then set it exactly

[psuedo code]
x1# = object angle x(a)
y1# = object angle y(a)
z1# = object angle z(a)
point object a, px#, py#, pz#
x2# = object angle x(a)
y2# = object angle y(a)
z2# = object angle z(a)
x3# = x1# + (x2# - x1#)*0.1
y3# = y1# + (y2# - y1#)*0.1
z3# = z1# + (z2# - z1#)*0.1
rotate object a, x3#, y3#, z3#
[/psuedo code]

There will be a little more playing around than that... wait... my memory just kicked in as I was thinking about EZ Rotate. I have some great rotation code from the forums... Here:


chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Dec 2011 12:11
Inflictive Studios

Do you mean somethin like that?


Cheers.

Login to post a reply

Server time is: 2024-04-24 21:04:31
Your offset time is: 2024-04-24 21:04:31