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.

Newcomers AppGameKit Corner / How to move an object in desired direction, regardless of it's orientation?

Author
Message
Rick Nasher
7
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 15th Oct 2017 10:46
Hi guys,

Say I want to use a capsule as a bullet, then I'm having an orientation problem:

When first creating a capsule it's a vertical object , while bullets would have to be horizontal.
If I just rotate the object 90 degrees over the x-axis it would look right, like this:



But unfortunately this *also* rotates it's x,y,z axis handle.
So if fired, normally one would just increase z, but that now no longer works, for axis have shifte90 degrees too.

Question: Is there in AppGameKit a way to move an object in the desired direction *regardless* of it's orientation,
or perhaps a way to change the x,y,z handles permanently?


In Blitz3D we used to have a great command for this:

Quote: "
TranslateEntity entity,x#,y#,z#,[,global]
Parameters
entity - name of entity to be translated
x# - x amount that entity will be translated by
y# - y amount that entity will be translated by
z# - z amount that entity will be translated by
global (optional) -

Description
Translates an entity relative to its current position and not its orientation.

What this means is that an entity will move in a certain direction despite where it may be facing. Imagine that you have a game character that you want to make jump in the air at the same time as doing a triple somersault. Translating the character by a positive y amount will mean the character will always travel directly up in their air, regardless of where it may be facing due to the somersault action.

"


Or one could also use this:
Quote: "
RotateMesh mesh,pitch#,yaw#,roll#
Parameters
mesh - mesh handle
pitch# - pitch of mesh
yaw# - yaw of mesh
roll# - roll of mesh

Description
Rotates all vertices of a mesh by the specified rotation.
"


Which would not rotate the axis. If no commands or solution exists than adding commands like these would really add to the AppGameKit language I think.

puzzler2018
User Banned
Posted: 15th Oct 2017 11:04
How does this sound?

MoveObjectLocalX, Y and Z
or
RotateObjectLocalX,Y and Z

D
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 15th Oct 2017 17:05 Edited at: 15th Oct 2017 17:08
rotate the object as desired when first setting it up and then call this
FixObjectPivot(id)
Resets the object's position and rotation to 0 whilst keeping the object's vertices where they are. This can be used to change the center of rotation of an object or adjust its default orientation when it's rotation is 0. This command modifies the vertices of the object's meshes so is not recommended to call this every frame, unless the target platform is quite powerful i.e. Windows, Mac, or Linux.

you can also use
MoveObjectLocalX(id,spd#)
MoveObjectLocalY(id,spd#)
or
MoveObjectLocalZ(id,spd#)
to move the object forward in any of it's own axis
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Rick Nasher
7
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 15th Oct 2017 19:18 Edited at: 15th Oct 2017 20:02
Thanks guys.

@puzzler2018: that doesn't work in general code for axis changed.
@smallg, FixObjectPivot(id) indeed did the trick, as you can see from below code snippet, which is 3d-ification of the 2d type/array example from the AppGameKit that uses sprites.
( Original here: https://www.appgamekit.com/documentation/guides/types_003.htm )



Full working example:

*I didn't clean it up, so don't look at the mess, it's just a quick typ/array test.


What is a bit silly : I actually already had used FixObjectPivot () before in another piece of code, that I forgot/ditched for I couldn't get what I want, which is clone an object with other objects linked to it.
Procedure:
1) create bullettip using: bulletip=CreateObjectCapsule(.2,.4,3)
2) create bulletshell using: bulletshell=CreateObjectCylinder(.4,.2,32)
3) tie both pieces together: FixObjectToObject(bulletshell,bulletip)
4) copy the whole thing: bullet=CloneObject(bulletip)
5) move it in desired direction: SetObjectPosition(bullet,10,5,10)

This doesn't work for somehow the FixObjectToObject command doesn't create a real child object apparently, so only the bulletip object will be copied.
Unfortunately this somehow limits the creation of examples with procedurally generated graphics.

Login to post a reply

Server time is: 2024-11-22 20:37:55
Your offset time is: 2024-11-22 20:37:55