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 / how do you swing a sword?

Author
Message
BF game programmer
20
Years of Service
User Offline
Joined: 22nd Jan 2005
Location: hoover alabama
Posted: 24th Aug 2005 05:11
hi i made a sphere with a limb (a box) that will act like a sword. but idont know how to make it swing. heres what i have so far


thanks! give me some code if you can

james bond rules and star wars
Leeorg
19
Years of Service
User Offline
Joined: 5th Jul 2005
Location:
Posted: 24th Aug 2005 11:59
Normally you would animate this using a 3D package then using the DB commands to use your animations at will, but you can do it this way.

You need a bit of maths like SIN & COS to work out a general X,Y pos for rotating an object round a point.
So... It works a little like this:

A hand made rotation works like this (from BBC BASIC (2D only))
X=10:Y=10 ` The radius of X & Y
For D=0 to 359raw X*SIN(D),Y*COS(D):NEXT D ` This will draw a circle.

Ok, next thing is to work out what two axies to use for this rotation.
I'll assume you have designed your object from facing the side, so you'll use the X & Y axis for rotation of the sword. Leave Z axis alone.
We'll say 0,0,0 is the point of origin, The Point Of Origin is important to work out from which point the sword will swing.
So XO is X Point Of Origin,
YO is Y Point Of origin, both =0. Z will always=0 for ease of use.
R is the Radius from XO & YO.(You can have an X & Y Radius for an oval type swing)
DS is degree start (from BBC BASIC, 0 degrees SIN & COS start at the top of a circle, so I'll assume the same for this but be aware it may be different.)
DE is degree end. DS=90 DE=270
So:
FOR D=DS to DEOSITION OBJECT <sword>,XO#+(R#*SIN(D)),YO#+(R#*COS(D)),ZO#:NEXT D
This will make the object move round a semi circle, but will not rotate it so a varible is needed to know if the sword is swinging forwwards or backwards therefore:
IF direction=forwards Then Pitch Object Up <sword>,1
IF direction=backwards Then Pitch Object Down <sword>,1
Last thing is to OFFSET the object at the correct position.

Ok, so the sword is limbed to the box so no matter what oreintation that the box is at, the sword will behave like its in its original position - if you know what I mean - and will swing.
You'll have to work out how you are going to code this, but the basics are there.

Hope this of use - anyfurther Q's I'll be happy to try and answer them.

Lee
BF game programmer
20
Years of Service
User Offline
Joined: 22nd Jan 2005
Location: hoover alabama
Posted: 24th Aug 2005 14:56
ill try that. thanks! but later on i will get a model for it this is just for now.

james bond rules and star wars

Login to post a reply

Server time is: 2025-05-29 05:31:52
Your offset time is: 2025-05-29 05:31:52