I'm working with a Trio Motion MC405 at work and no matter what I do, I can't get the axis to move.
WDOG = OFF
BASE(0)
ATYPE = 43 'STEPPER
SPEED = 5000
ACCEL = 100000
DECEL = 150000
SERVO = ON;
WDOG = ON
MOVE(30) AXIS(0)
Has anyone played with Motion Perfect V3.3, I'd appreciate any help.
Related
what is happening is that my "enemy" is not following the "player", when my player enters the detection area the "enemy" continues straight ahead (to the left).
thank you, if you understand something or need more information let me know
detection zone
enemy code
enemy code:
const EnemyDeathEffect = preload("res://Bots/EnemyDeathEffect.tscn")
export var MAX_SPEED = 60
export var ACCELERATION= 25
export var FRICTION = 700
enum {
IDLE,
WANDER,
CHASE
}
var velocity = Vector2.ZERO
var knockback = Vector2.ZERO
var state = CHASE
var path: PoolVector2Array
onready var sprite = $AnimatedSprite
onready var stats = $Stats
onready var playerDetectionZone = $PlayerDetectionZone
func _physics_process(delta):
knockback = knockback.move_toward(Vector2.ZERO, FRICTION * delta)
knockback = move_and_slide(knockback)
match state:
IDLE:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
seek_player()
WANDER:
pass
CHASE:
var player = playerDetectionZone.player
if player != null:
var direction = (player.position - global_position).normalized()
velocity = velocity.move_toward(direction * MAX_SPEED , ACCELERATION * delta)
print(direction)
else:
state = IDLE
sprite.flip_h = velocity.x > 0
velocity = move_and_slide(velocity)
func seek_player():
if playerDetectionZone.can_see_player():
state = CHASE
func _on_Hurtbox_area_entered(area):
stats.health -= area.damage
knockback = area.knockback_vector * 100
func _on_Stats_no_health():
queue_free()
var enemyDeathEffect = EnemyDeathEffect.instance()
get_parent().add_child(enemyDeathEffect)
enemyDeathEffect.global_position = global_position
I only possible culprit I see is this line:
var direction = (player.position - global_position).normalized()
Here player.position is in its parent local coordinates, while global_position as the name says is in global coordinates. You want this instead:
var direction = (player.global_position - global_position).normalized()
I see this is the way you have on the linked image.
Or if you prefer:
var direction = global_position.direction_to(player.global_position)
Aside from that, it could be that it is changing direction too slowly. Which - given the code - is the same as saying that the ACCELERATION is low, but that is for you to tweak.
I guess it is worth debugging that playerDetectionZone is getting the player, and the CHASE is working correctly.
Common approaches include using a breakpoint, or print. You already have a print for direction. Try also printing player to check the enemy is chasing what you expect it to chase.
For this particular case I also suggest to go to the run the project from the editor, and then go to the Scene panel on the Remote tab, and select the enemy. That would allow you to the properties of the enemy on real time on the Inspector. You should see the state change to CHASE (which would have the value 2), and velocity should also steadily change.
Enabling "Visible Collision Shapes" form the debug menu may also help debugging.
If it is not working, double check the playerDetectionZone has monitoring enabled. Also check that the collision_mask of the playerDetectionZone and the collision_layer of the player are correct.
anyone knows in what consist scale in svglib ? whats the measure ? I don't get what correspond the 10 in this example, is it pixel, inch ... ?
Thank you for your help
drawing = svg2rlg(StringIO(textwrap.dedent('''
{}'''.format(xml_svg))))
# scale https://github.com/deeplook/svglib/issues/207
sx = sy = 10
drawing.width, drawing.height = drawing.minWidth() * sx, drawing.height * sy
drawing.scale(sx, sy)
I need some help with a quiete simple problem in FiPy. My goal is to simulate a fluid flowing through a concrete block while phase change.
But first of all I tried to do a simple 1D simulation assumed a fluid massflow and a constant wall temperature without any phase change.
from fipy import *
from fipy.meshes import CylindricalGrid2D, Grid1D
import matplotlib.pyplot as plt
import numpy as np
#%%
L = 1.5 #length transfer surface
bS = 0.75 #wide
AV = L * bS #transfer surface
tS0 = 350. #tWall
rhoWF = 880. #density fluid
mWF = 0.036 #mass flow
u = 5e-4 #Fluid speed
hWF = mWF / AV / rhoWF / u #height "fluid block"
nx = 50
VWF = hWF * L * bS/nx #fluid volumen
lambdaWF = 0.6 # thermal conductivity
alpha = 500. #heat transfer coefficient
tWF0 = 371.
mesh = Grid1D(dx=L/nx, nx=nx)
tWF = CellVariable(name="Fluid",
mesh=mesh,
value= tWF0,
hasOld=True)
tS = CellVariable(name="storage",
mesh=mesh,
value=tS0,
hasOld=True)
sourceWF=CellVariable(name="source Fluid", #Variable der Konvektion
mesh=mesh,
value=0.)
cvrho = CellVariable(name = 'cprho',#Fluid
mesh = mesh,
value = rhoWF * 4215.2,
hasOld = True)
tWF.constrain(tWF0, mesh.facesLeft()) #constant inlet temperature
t = 6*3600. #time
timeStepDuration = 1e2
#outflow boundary condition
outlet = mesh.facesRight
ConvCoeff = FaceVariable(mesh,value=u,rank=1)
exteriorCoeff = FaceVariable(mesh,value=0.,rank=1)
exteriorCoeff.setValue(value=ConvCoeff, where=outlet)
ConvCoeff.setValue(0., where=outlet)
residual1 = 1.
elapsedTime = 0.
tWFall = np.zeros(nx)[None,:]
while elapsedTime < t:
tWF.updateOld()
it = 0 #iterations
while residual1> 1e-2:
sourceWF.value = - AV / nx * alpha*(tWF - tS)/ cvrho / VWF #this will be a variable convection source
eq1 = HybridConvectionTerm(coeff=ConvCoeff) + TransientTerm(coeff=1.) == \
+ sourceWF\
- ImplicitSourceTerm(exteriorCoeff.divergence) \
#+ DiffusionTerm(coeff= lambdaWF / cvrho) #not necessary(?)
residual1 = eq1.sweep(dt = timeStepDuration, var = tWF)
print('res1: ' + str(residual1) )
it += 1
if it > 10:
raise ValueError (r'MaxIter reached')
elapsedTime += timeStepDuration ; print('t= ' + str(round(elapsedTime,2)))
residual1 = 1.
tWFall = np.r_[tWFall, tWF.value[None,:]] #value collection
#%% outlet fluid temperature and storage temperature
plt.plot(np.linspace(0,t/3600.,int(t/timeStepDuration)), tWFall[1:,-1], label=r'$\vartheta_{WF}$')
plt.legend()
I would expect a constant fluid outlet temperature because of the constant wall temperature and constant fluid inlet temperature. I have not defined the wall temperature as a boundary condition because some day I would like to analyse heat conduction and variable temperature gradients too. Running my mwe you can see that the fluid temperature at the outlet declines.
Could someone please help at this case?
Thanks in advance!
I changed the script around and it seem to give a constant temperature of 371.0. See this link.
The sourceWF term has been removed. I was unsure what this was for, but I think it would take time for the wall temperature to adjust to this.
The equation declaration has been moved outside the loop. This is the correct way to use FiPy, but shouldn't impact the results in this case.
I am learning game programming with Phaser and I am currently building a simple breakout game.
When the ball hits the paddle I use the following code to determine the new x velocity of the ball:
if (ball.x < paddle.x)
{
// Ball is on the left-hand side of the paddle
diff = paddle.x - ball.x;
ball.body.velocity.x = (-10 * diff);
}
else if (ball.x > paddle.x)
{
// Ball is on the right-hand side of the paddle
diff = ball.x -paddle.x;
ball.body.velocity.x = (10 * diff);
}
else
{
// Ball is perfectly in the middle
// Add a little random X to stop it bouncing straight up!
ball.body.velocity.x = 2 + Math.random() * 8;
}
This code is originally taken I believe from stackoverflow, although I cannot remember from which post I'm afraid.
The problem with this is that when the ball goes left or right at an angle, it appears faster on screen than if it goes straight up. The more pronounced the angle, the faster it goes and appears.
Does anyone know how to solve this problem?
Regards
Crouz
The speed of the ball is given by a combination of the horizontal (x) speed and vertical (y) speed, as given by Pythagoras' theorem:
z2 = x2 + y2
where overall speed would be z.
If you increase x without decreasing y appropriately, then the overall speed will also increase.
If you want the speed to remain the same, then you need to adjust y as well. Example pseudo-code:
speed = sqrt(x^2 + y^2)
x = 2 + random()*8
y = sqrt(speed^2 - x^2)
You could incorporate this into your code by calculating speed before any adjustments are made, and then adjusting y afterwards:
// Calculate overall speed
var speed = Math.sqrt(
Math.pow(ball.body.velocity.x, 2) +
Math.pow(ball.body.velocity.y, 2)
);
if (ball.x < paddle.x)
{
// Ball is on the left-hand side of the paddle
diff = paddle.x - ball.x;
ball.body.velocity.x = (-10 * diff);
}
else if (ball.x > paddle.x)
{
// Ball is on the right-hand side of the paddle
diff = ball.x -paddle.x;
ball.body.velocity.x = (10 * diff);
}
else
{
// Ball is perfectly in the middle
// Add a little random X to stop it bouncing straight up!
ball.body.velocity.x = 2 + Math.random() * 8;
}
// Adjust y to maintain same overall speed
ball.body.velocity.y = Math.sqrt(
Math.pow(speed, 2) -
Math.pow(ball.body.velocity.x, 2)
);
This will always result in a positive y, so you might need to negate it depending on which direction (up or down) you want it to be moving.
I'm developing my first game with SpriteKit and I need to shoot a laser beam. I don't know how to do this since I don't know the size of the laser sprite, does it have to be with size of the screen height and crop the image when a collision is detected? can anyone point me to the right directions please? Have no idea about this XD
Thanks for your comments :D
This could be done by line-of-sight detection system described here in the section Searching for physics bodies :
Useful method would be enumerateBodiesAlongRayStart:end:usingBlock: from SKPhysicsWorld class which enumerates all the physics bodies in the scene that intersect a ray.
Basically you have to set start point and search for end point using the method above.When you know where is the intersection point(end point of laser beam) you can easily draw it.
This is a way late response, but I've got a really nice solution. Here's what it looks like (Swift 3):
In my code I'm calling this when I rotate the node I want the laser to shoot out of:
self.laser = SKShapeNode()
laser.lineWidth = 6
laser.glowWidth = 8
laser.strokeColor = .red
let _ = isTargetVisibleAtAngle(startPoint: startPoint, angle: selectedBeam!.zRotation + (CGFloat.pi / 2), distance: frame.size.height)
And this is the method. Obviously you put in whatever angle you want. The "foundOne" thing is so that it stops on the first object if that ray crosses through multiple targets
func isTargetVisibleAtAngle(startPoint: CGPoint, angle: CGFloat, distance: CGFloat) -> Bool {
let rayStart = startPoint
let rayEnd = CGPoint(x: rayStart.x + distance * cos(angle),
y: rayStart.y + distance * sin(angle))
let path = CGMutablePath()
path.move(to: rayStart)
path.addLine(to: rayEnd)
laser.path = path
var foundOne = false
let _ = physicsWorld.enumerateBodies(alongRayStart: rayStart, end: rayEnd) { (body, point, vector, stop) in
if !foundOne {
foundOne = true
let p = CGMutablePath()
p.move(to: rayStart)
p.addLine(to: point)
self.laser.path = p
}
}
return false
}