Post new topic    
Liquid Metal Slime
Send private message
Is it unwise to use calculus? 
 PostFri Mar 06, 2015 6:17 am
Send private message Reply with quote
So in order to create a curved border of an area to block the character, simulating walls, I've begun an attempt to use scripts to simulate functions an use a bit of calculus in order to determine coordinates along the curve. I suppose I'll find out, but is that a bit too complicated for the OHR to use efficiently? I mean, I'm going to try either way, but I just want to know if I'm stupid for doing so.
My pronouns are they/them
Ps. I love my wife
Liquid Metal Slime
Send private message
Re: Is it unwise to use calculus? 
 PostFri Mar 06, 2015 6:37 am
Send private message Reply with quote
kylekrack wrote:
So in order to create a curved border of an area to block the character, simulating walls, I've begun an attempt to use scripts to simulate functions an use a bit of calculus in order to determine coordinates along the curve. I suppose I'll find out, but is that a bit too complicated for the OHR to use efficiently? I mean, I'm going to try either way, but I just want to know if I'm stupid for doing so.


I'm assuming by calculus you mean you are creating a curve by having your code mathematically solve the curvature based on altering the rate of change in the x and y axis. This is commonly referred to as a Bezier Curve and is pretty useful for making curves. You should search up Bezier Curve and see all the neat related Bezier stuff you can do. There's lots of math formulas on the wiki for it, sometimes even code. So you don't have to completely start from scratch with the code either.

This shows animations on how Bezier changes 2 straight lines in to one curve (or more) http://en.wikipedia.org/wiki/B%C3%A9zier_curve

I suppose it's more a matter of how you make your curve function behave with your character. I presume each pixel of the curve will somehow block the character? If so I'm curious to see how you pull that off, I've never really thought too much about how that sort of thing may work.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Metal King Slime
Send private message
 
 PostFri Mar 06, 2015 6:53 am
Send private message Reply with quote
If you want, I've got code for bezier curves. I'm using it to throw projectiles around in my combat engine, but you might be able to use it to get the values you want.
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Liquid Metal Slime
Send private message
 
 PostFri Mar 06, 2015 7:14 am
Send private message Reply with quote
BMR wrote:
If you want, I've got code for bezier curves. I'm using it to throw projectiles around in my combat engine, but you might be able to use it to get the values you want.


Oh yeah! I definitely remember seeing the video clip of that. Looked very well done.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Liquid Metal Slime
Send private message
 
 PostFri Mar 06, 2015 7:35 am
Send private message Reply with quote
Ok I'm using straight lines (it's a boxing arena shaped like this: / \ ). On either side the lines have a slope of 4, so I'm saying if the player's x coordinate is less than or equal to (x/4)+6), then you aren't allowed to move. I'm really tired, so I don't think I'm anywhere on the right track, but uh, here's one of the scripts.

Code:

script, try left, begin
   left wall
   if(not(blocked)) then(
      set slice velocity x(buff,-4,1)
   )
end

script, left wall, begin
   variable(x)
   if(slice x(feet) <= ((x/4)+6)) then(
      blocked := true
   )
end


Also how do you make something negative? Can you just put - in front of the number? It didn't seem to work, although looking at it now, I put it outside the parentheses.

I'm having difficulty wrapping my head around the syntax and whatnot that goes along with using code. It's a lot different from doing it on pencil and paper, so I think I just need to figure out what's going on. But if I get this to work, I'll try to do the same thing with a parabola and post a tech demo or something for anyone who's interested. I remember Gun Pigs intends to have pixel based movement, so maybe I can help out with that. I'm tryin to do the same sort of thing here. Man, I've started rambling. I need to go to bed.
My pronouns are they/them
Ps. I love my wife
Metal King Slime
Send private message
 
 PostFri Mar 06, 2015 8:16 am
Send private message Reply with quote
Hamsterspeak doesn't have a negation operator. Write -1*x or 0--x instead.

BTW, you can use fixed point numbers to represent fractional values. It's doable but annoying and requires being careful. I like to multiply everything by 1000, and write 3 500 for 3.5, -1 000 for -1 etc.
Liquid Metal Slime
Send private message
 
 PostSat Mar 07, 2015 8:15 pm
Send private message Reply with quote
Ok so I've been trying to comprehend what exactly I'm trying to do and I've been working many different ways. Ultimately, all ending in complete failure.

BUTT, I've reached the point where the walls at least stop the player. Given, it prevents any leftward movement, but still, it's progress.

Code:

script, try left, begin
   left wall
   dir := left
   horiz flip sprite(buff,false)
   put slice(hitbox,15,8)
   put slice(feet,12,38)
   put slice(punchbox,-10,13)
   animate walking
   if(not(blocked)) then(
      set slice velocity x(buff,-4,1)
   )
end

script, left wall, begin
   variable(x,y,feetx)
   feetx := slice x(feet)
   #y := 4*(feetx+50)
   if(slice y(feet) <= (4*(feetx+50))) then(
      blocked := true)
   else(blocked := false)
end


Ok, so this attempts to make it so that if the player's feet are at a point which falls on the line 4(x+50), or goes beyond it, then the player should be stopped. I'm trying to figure out exactly how the flipped y-axis changes everything and how to apply that. I have a strong feeling I'm just going about this the wrong way, so I'm going to rely on someone else to tell me what I'm doing wrong.
My pronouns are they/them
Ps. I love my wife
Liquid Metal Slime
Send private message
 
 PostSat Mar 07, 2015 8:27 pm
Send private message Reply with quote
Sorry I'm a bit confused, could you define the problem more? What I understand is the code is for a left wall (a wall to the left of the hero) and you are saying that it works (meaning it blocks you from moving left) so is there a problem with how this is working? Or are you just saying now that you have got that to work, you'd like to flip it so that you can do the same with right walls...?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Liquid Metal Slime
Send private message
 
 PostSun Mar 08, 2015 4:44 am
Send private message Reply with quote
Sorry I wasn't very clear with that. With this code, the player can't move left at all.
My pronouns are they/them
Ps. I love my wife
Metal King Slime
Send private message
 
 PostSun Mar 08, 2015 10:19 am
Send private message Reply with quote
I notice that this wall covers almost all of the map; that's probably the problem. That line starts at the left edge of the map 200 pixels from the top and slopes steeply down; everything above it is in the wall.

Because y increases downwards and x to the right, when thinking of a graph of a function you need to flip it over the x axis to see its position on the map. This is confusing, so you could undo this flip, having (0,0) at the bottom left corner, by writing feety := mapheight*20 - slicey(feet).


Alternatively, I think you're better off defining your wall segments with start and end point (or three points for a parabola, or whatever else) instead of trying to directly write down an equation for it, and write a script which calculates whether it's in the wall based on that. (Of course, line segments and infinite lines are different things, which needs to be considered if you want convex wall shapes.) then you could just use map co-ordinates for everything, and get those from the map editor.

Also, it's suspicious that you call "left wall" before your test code which places the 'feet' slice.
Display posts from previous: