Jump to content

Crazy Ball Game - Physics Problem


CoolBeans
 Share

Recommended Posts

Ok so I'm trying to learn some of the crazy ball game Josh posted. I know there will be some

material he is going to make for it in the future release of Leadwerks but I couldn't help but

to try and get started on my own. Wasn't the exact game Id like to make but I see some

mechanics I may be able to apply and learn here form prior tutorials. Ive got the ball and

camera working.

 

Here is the script some it I found here in a post.

Script.camera = "" --entity "Camera"

Script.soundfile1=""--path "Sound 1" "Wac file (*.wav):wav|Sound"

Script.soundfile2=""--path "Sound 2" "Wac file (*.wav):wav|Sound"

Script.soundfile3=""--path "Sound 3" "Wac file (*.wav):wav|Sound"

Script.soundfile4=""--path "Sound 4" "Wac file (*.wav):wav|Sound"

Script.threshhold=2--float "Threshhold"

Script.maxfrequency=300--minimum delay between sound plays

Script.range=20--float "Range"

 

--Global values

ImpactNoiseLastSoundTime=0-- This will be shared among all instances of this script and ensure we don't play too many sounds

 

 

 

function Script:UpdateWorld()

local window = Window:GetCurrent()

if window:KeyDown(Key.W) then self.entity:AddForce(0,0,10,true) end

if window:KeyDown(Key.S) then self.entity:AddForce(0,0,-10,true) end

if window:KeyDown(Key.A) then self.entity:AddForce(-10,0,0,true) end

if window:KeyDown(Key.D) then self.entity:AddForce(10,0,0,true) end

if window:KeyHit(Key.Space) then self.entity:AddForce(0,300,0,true) end

self.camera:SetPosition(self.entity:GetPosition(true) + Vec3(0,3,-6))

end

 

function Script:Start()

self.sound={}

for n=1,4 do

local filepath = self["soundfile"..tostring(n)]

if filepath~="" then

local noise = Sound:Load(filepath)

if noise~=nil then

table.insert(self.sound,noise)

--self.sound[#self.sound+1]=noise

end

end

end

end

 

function Script:Collision(entity, position, normal, speed)

if speed>self.threshhold then

if #self.sound>0 then

local collisiontype = entity:GetCollisionType()

if collisiontype==Collision.Prop or collisiontype==Collision.Scene then

local t = Time:GetCurrent()

if t-ImpactNoiseLastSoundTime>self.maxfrequency then

ImpactNoiseLastSoundTime=t

local n=math.random(#self.sound)

local noise = self.sound[n]

self.entity:EmitSound(noise,self.range)

end

end

end

end

end

 

 

Brings me to my first question.

Where is the default camera when you make a scene? When I create a camera its always camera 2

so I presume a default cam is always added and hidden from scene objects list?

 

First problem I'm dealing with is ball creation. Its never perfectly round. When rolling around the ball

it skips and makes sounds of course. In 3dmax u can scale an object uniform on xyz at the same time.

I cant seem to do that in Leadwerks? Ive tried grid snap and no grid snap always a ball that wobbles.

Well its a stone ball for now so its ok lol. Seriously why?

 

Second Ive kinda set up what Josh has initially in the game. 2 blades spinning opposite. When my ball

is in motion it reacts fine to the blades. Makes sound, get forced away etc. But.. When the ball is idle

the blades go right thru the ball like its not there instead of applying force/movement. I have played with

different prop types, mass and what not and have got some crazy results ranging from...

Ball falls thru platform, ball hits blade, blade moves and still spins till blade goes crazy off the map.

Blade just spins weird from the get go or falls itself.

 

I have the ball set - Rigid body, sphere get shape fit physics, mass 1.0, collision prop nothing checked marked after. As for the rotating blades ive tries all combo's I can conjure and have not found the right one.

 

I can't make a screen shot of the game running via print screen is there a Leadwerks feature for that?

 

After this point Im going to try and apply the death trigger script from Jorn's tutorial if the balls falls off.

If I get this far I know the next step will be wanting to learn the count meter to start, how to collect the

objects and count them in the score ect if anyone can provide any links/material for this dirrection

would be awesome, thanks a lot for any help.

Link to comment
Share on other sites

i will try to help as i already did a small demo game with that mechanic a while ago.

 

first i don´t think there is any default camera. Not sure why the first camera you create gets named Camera 2. But if you don´t create a camera you will see nothing at all.

 

 

the most important thing i guess is that you try to make the ball directly in the editor.

 

What i noticed a couple of times is that the CSG Objects always behave oddly in some ways.

 

For example physics do not apply to them the same way as imported models from a external 3d model program would do.

I have a box in one of my demo levels that got the same physics option as a real 3d model got. The real 3d model falls down to the ground from the start.

 

The leadwerks box is still stuck in the air.

 

It is surely nice for some small things to do that, but i recommend using a real 3d model for your main gameplay part like the ball. Creating a sphere should be relatively easy in every 3d modeler out there.

 

As far as i have seen even Josh actually created a real 3d model in his demo.

Link to comment
Share on other sites

There must be a default camera. Odd. I can make a new project place a platform press play and see fine no camera made.

 

Anyways I made a sphere in 3dsmax 2015 with 64 segments. Learned how to export the FBX file. Imported as a mdl file

to Leadwerks and its as smooth as GLASS now! Woot! Progress in the smallest form is rewarding muhahaha ok ok...

I noticed in Leadwerks you can only make 32 segments. If I import a model with 64 is it down graded to 32?

 

Still cant figure out these physics. Also dragging 3dsmax .mat files into the Leadwerks mat file dir doesn't work?

I get blank materials when I try to open them in Leadwerks after.

 

Thanks

CB

Link to comment
Share on other sites

Do you have the first person prefab in your scene? A camera is made in code in that script.

 

As far as I know material files are per application. ie they aren't all the same so a .mat in 3dsmax isn't the same as in leadwerks. It's just like the .mdl format. Other engines use that format but they aren't all the same and can't be used between engines.

 

The segments are only for CSG creation. Your model can be as detailed as you want but the more detailed the longer the load and more memory and such. With just a sphere you probably won't have much issue with that though.

Link to comment
Share on other sites

Thanks for the info. I don't have a first person prefab. I just created a new project. Made a box. Added a camera. Its camera 2 again. Good to hear on segments in LW Ill be spending much more time in 3dsmax'

 

I did get spawning to work via death trigger script from Jorns tutorial and renaming from Player to ball so when I roll off I start over at least wink.png

 

Anyways I'm still having the problem if the ball is idle / not moving the blades sweep right thru the ball not moving it.

 

I'm also now stuck trying to get a collision to work. If I roll over a small box for example with the ball, the box makes a sound and disappears. Entity(hide) rather. Later to be added to the goal count or score count. What little script can I add to the object?

I tried dissecting the pickupobject script from the FPS character but it has prefab coding in there and I got a bit lost...

 

Thanks again for any help fellas.

CB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...